【问题标题】:refresh parent page from child page not working从子页面刷新父页面不起作用
【发布时间】:2016-11-17 20:15:35
【问题描述】:

好吧,这让我发疯了。我尝试了任何可能的解决方案,但都不起作用。

问题来了:

我的父页面中有一个gridview。每行都有一个“编辑”按钮,可以打开一个新页面:

<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\");") %> '/>

在子页面中,我从 db 填充所有字段,然后单击“更新”将所有数据保存到 dab 并关闭当前页面:

<script>
        function RefreshParent() {

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

Button1 包含一个从 db 刷新 Gridview 数据的方法。

我尝试了以下代码,但它没有刷新 gridview:

window.opener.location.reload(true);

这是我父窗口中gridview的定义:

<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>

感谢任何支持。

【问题讨论】:

标签: c# asp.net popupwindow aspxgridview


【解决方案1】:

这真的很有趣。 我用下面的代码解决了这个问题。这可以防止 javascript 函数在 C# 更新之前运行。

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

然后你需要把它添加到你的代码后面的.cs中

refresh_script.Visible = true;

【讨论】:

    猜你喜欢
    • 2011-02-12
    • 1970-01-01
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多