views:

22

answers:

2

In my form I have a label and button control. By default the label is visible. When a user clicks on the button I have made the label to visible false. For simple button it is working, but when I add an updatePanel to button the event is getting fired but the label is not getting to visible false. Just try this, and please can anybody tell me why this is happening and the solution for this.

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

From the looks of it you need to wrap your label within the update panel as well.

Try

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

An update panel will update a section of your page. Your label wasn't included within the updatepanel so would never get updated with your new value.

mjmcloug
A: 

I suggest that you only wrap the label with the UpdatePanel and set the UpdateMode to "Conditional".

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

Regards.

uvita