简体   繁体   中英

refresh parent page from child page not working

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM