0

Ok , this is running me nuts. I have tried any possible solution and it is not working.

Here is the problem:

I have a gridview in my parent page. Each row has an "Edit" button which opens a new page:

<asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName=""  Text="Edit" OnClientClick='<%# Eval("ID", "window.open(\"EditFrm.aspx?ID={0}\", null, \"width=700,height=600,top=100,left=300\", \"true\");") %> '/>

in Child page, I populate all the fields from db and with clicking on "update" save all the data into dab and close the current page:

<script>
        function RefreshParent() {

            window.opener.document.getElementById('Button1').click();
            window.close();
        }
</script>    

Button1 includes a method to refresh Gridview data from db.

I have tried following code but it doesn't refresh the gridview:

window.opener.location.reload(true);

Here is the definition of gridview in my parent window:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                 <asp:ScriptManager ID="ScriptManager1" runat="server">
                 </asp:ScriptManager>
                <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" AutoGenerateDeleteButton="True"  OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting"  BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical">
                    <AlternatingRowStyle BackColor="#DCDCDC" />
                    <Columns>
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>

                                <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName=""  Text="Edit" OnClientClick='<%# Eval("ID", "window.open(\"EditFrm.aspx?ID={0}\", null, \"width=700,height=600,top=100,left=300\", \"true\");") %> '/>
                            </ItemTemplate>
                        </asp:TemplateField>

// Column definition


            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="GridView1" />
            </Triggers>
        </asp:UpdatePanel>

Any support is appreciated.

Navid
  • 223
  • 1
  • 7
  • 18
  • Possible duplicate of [How to run function of parent window when child window closes?](http://stackoverflow.com/questions/1777864/how-to-run-function-of-parent-window-when-child-window-closes) – emerson.marini Nov 17 '16 at 20:24

1 Answers1

0

This was really interesting. I solved the problem with following code. This prevents javascript function to run before C# update.

<asp:placeholder id="refresh_script" visible="false" runat="server">
                    <script>           
                        window.opener.location.reload();
                        window.close();                    
                    </script> 
                  </asp:placeholder>   

Then you need to add this to your code behind in .cs

refresh_script.Visible = true;
Navid
  • 223
  • 1
  • 7
  • 18