Reputation: 331
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!
Upvotes: 0
Views: 2995
Reputation: 7266
Add this after your </ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Change" EventName="Click" />
</Triggers>
Upvotes: 2
Reputation: 8359
You have set the updateMode property to Conditional
so it will the updatePanel won't be refreshed automatically (as this was default)!!
Simpel solution set it back to Always
MSDN UpdateMode
Always
The content of the UpdatePanel control is updated for all postbacks that originate from the page. This includes asynchronous postbacks.
Conditional
The content of the UpdatePanel control is updated under the following conditions:
If the Update method of the UpdatePanel control is called explicitly.
If a control is defined as a trigger by using the Triggers property of the UpdatePanel control and causes a postback. In this scenario, the control is an explicit trigger for updating the panel content. The trigger control can be either inside or outside the UpdatePanel control that defines the trigger.
If the ChildrenAsTriggers property is set to true and a child control of the UpdatePanel control causes a postback. In this scenario, child controls of the UpdatePanel control are implicit triggers for updating the panel. Child controls of nested UpdatePanel controls do not cause the outer UpdatePanel control to be updated unless they are explicitly defined as triggers.
See MSDN for further details!
Upvotes: 0