c#
  • asp.net
  • popupwindow
  • aspxgridview
  • 2016-11-17 59 views 0 likes 
    0

    好吧,這是讓我瘋狂。我試過任何可能的解決方案,它不工作。從子頁面刷新父頁面不工作

    這是問題:

    我在我的父頁面有一個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\");") %> '/> 
    

    在兒童頁,我填充所有從數據庫中的字段,並單擊「更新」保存所有數據到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> 
    

    任何支持表示讚賞。

    +0

    可能重複://計算器。 COM /問題/ 1777864 /如何對運行功能的父窗口,當孩子用窗關閉) – melancia

    回答

    0

    這真的很有趣。 我用下面的代碼解決了這個問題。這可以防止JavaScript函數在C#更新之前運行。

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

    然後,你需要在這背後的.cs添加到您的代碼[如何在子窗口關閉運行的父窗口的功能?(HTTP的

    refresh_script.Visible = true; 
    
    相關問題