Add triggers to an update panel in code how?

I

Ilyas

Hi all

I have the following in my .aspx

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

<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<asp:Label runat="server" ID="lbl1" Text="Time will go
here..." />
</ContentTemplate>
</asp:UpdatePanel>

<asp:Button runat="server" id="btn1" OnClick="btn1_OnClick"
Text="Get time" />

and in my code behind I have:

protected void Page_Load(object sender, EventArgs e)
{
AsyncPostBackTrigger t = new AsyncPostBackTrigger();
t.ControlID = btn1.ID;
UpdatePanel1.Triggers.Add(t);
}

protected void btn1_OnClick(object sender, EventArgs e)
{
lbl1.Text = DateTime.Now.ToString();
}

Now when I click the button, the first request is made using ajax, if
I click again the next request does a full postback and this
alterntates everytime

Can anyone explain why? I want to add async triggers through code (I
know you can do it in the .aspx) but I dont want a full page postback

Many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top