2016-08-01 107 views
0

在我的主頁面我有一個div「ErrorDiv」,我想從我的內容頁面調用以顯示我的錯誤。問題是,如果一個按鈕被包含在更新面板中,當我從後面的代碼調用它時div不會顯示。我相信有一個技巧來解決這個問題,我感謝你的幫助。 下面是我的代碼:內容頁面中的內容面板中的按鈕不能從主頁面調用div來顯示

母版頁:

<asp:Panel ID="pnlMainForm" runat="server"> 
<form id="form1" runat="server" > 
<asp:Panel id="CommonPanelError" runat="server" CssClass="alertMSG"  
    visible="false"> 
    <div id="ErrorDiv" class="ErrorBox" > 
    <table> 
    <tr style="vertical-align:top"> 
    <td><img src="../Images/Icons/error.png" alt="" style="vertical-    
     align:middle" id="img2" runat="server" />&nbsp&nbsp </td> 
    <td style="width:200px"> 
     <span style ="font-weight :bold ">ERROR</span><br /> 
     <asp:Label id="errorMsgBox" runat="server" > errorTest 
     </asp:Label> 
    </td> 
    <td>&nbsp&nbsp&nbsp&nbsp <a href ="#"><img onclick="CloseMyErrorBox();" 
     id ="closeErrorBox" src="../Images/Icons/warning4.png" alt=""  
     runat="server" /></a> 
    </td> 
    </tr> 
    </table> 
    </div> 
    </asp:Panel> 
</form> 
</asp:Panel>   

內容頁:

<asp:UpdatePanel ID="UPAll" runat="server"> 
<ContentTemplate> 
    <asp:Panel ID="pnlInsuredID" runat="server"> 
    <asp:LinkButton ID="lnkBtnphyCode" runat="server"> 
    <asp:Image ID="Image3" runat="server" ImageUrl="~/images/BAL/go.gif" /> 
    </asp:LinkButton> 
    </asp:Panel> 
</ContentTemplate> 
</asp:UpdatePanel> 

我的內容頁面的後臺代碼:

Protected Sub lnkBtnphyCode_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBtnphyCode.Click 

If Trim(txtPhysicianCode.Text) = "" Then 
    Dim c As Panel = CType(Me.Master.FindControl("CommonPanelError"), Panel) 
     If c IsNot Nothing Then 
      c.Attributes.Add("display", "block") 
     End If 
    Dim c1 As Label = CType(Me.Master.FindControl("errorMsgBox"), Label) 
    Dim str = c1.Text 
    errDotNet(str) 
else ... 

NB:errDotNet是一個函數提醒消息「str」,在我們的例子中顯示「errorTest」,這是insi的消息箱子裏。

回答

0

必須的ContentTemplate

<Triggers> 
    <asp:PostBackTrigger ControlID="lnkBtnphyCode" /> 
</Triggers> 

後把觸發更新面板內它需要完整的頁面請求。因此,在您的頁面加載中加入以下行:

ScriptManager.GetCurrent(Me).RegisterPostBackControl(Me.YourControlID); 
+0

您能添加一個小解釋嗎? @GalaxMan –

+0

最後我解決了這個問題。我發現爲包含圖像的鏈接按鈕添加觸發器不起作用。它應該是一個asp Button或一個鏈接按鈕 –