Search code examples
c#asp.netasp.net-ajaxupdatepanel

Change text in UpdatePanel


I am new with ASP.NET. This is my code:

 <asp:UpdatePanel runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Button Text="Change" runat="server" ID="BtnChangeText" OnClick="BtnChangeText_OnClick"/>
            <asp:Label runat="server" ID="LblTest" Text="Change me!"></asp:Label>        
        </ContentTemplate>          
 </asp:UpdatePanel>

This is my server code:

    protected void BtnChangeText_OnClick(object sender, EventArgs e)
    {
        LblTest.Text = "Hello World!";
    }

Why does it not work?. How can I do for this work?

Thank in advance!


Solution

  • Add this after your </ContentTemplate>

    <Triggers>         
      <asp:AsyncPostBackTrigger ControlID="Change" EventName="Click" /> 
    </Triggers>