2010-08-13 43 views
0

在我的表單中我有一個標籤和按鈕控件。 默認情況下,標籤是可見的。當用戶點擊按鈕時,我已將標籤設置爲可見。 對於簡單的按鈕它正在工作,但是當我添加一個updatePanel到按鈕時,事件被激發,但標籤沒有變爲可見的假。試試這個,請任何人都可以告訴我爲什麼會發生這種情況以及解決方案。關於更新面板的困惑

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>  

<asp:fileupload ID="Fileupload1" runat="server"></asp:fileupload>  
<asp:Label ID="Label1" runat="server" Text="Label" ></asp:Label>  
<asp:UpdatePanel ID="up" runat ="server" > 
    <ContentTemplate > 
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 
    </ContentTemplate> 
</asp:UpdatePanel> 

protected void Button1_Click(object sender, EventArgs e) 
{ 
    Response.Write("hello"); 
    Label1.Visible = false; 
} 

回答

1

從外觀上看,您還需要在更新面板中包裝您的標籤。

嘗試

<asp:fileupload ID="Fileupload1" runat="server"></asp:fileupload> 
<asp:UpdatePanel ID="up" runat ="server" >  
    <ContentTemplate> 
     <asp:Label ID="Label1" runat="server" Text="Label" ></asp:Label>  
     <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 
    </ContentTemplate> 
</asp:UpdatePanel> 

更新面板將更新頁面的一部分。您的標籤不包含在更新面板中,因此永遠不會更新您的新值。

0

我建議你只用UpdatePanel包裝標籤並將UpdateMode設置爲「有條件」。

<asp:UpdatePanel ID="up" runat ="server" UpdateMode="Coditional" >  
    <ContentTemplate> 
     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>     
    </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="Button1" /> 
    </Triggers> 
</asp:UpdatePanel> 
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> 

問候。