Updatepanel Triggers

 

Generally update panel avoids the post back of the page. But sometimes we may have requirement like for particular button click in the update panel, total page has to refresh. In this type scenario we can use triggers to refresh the total page.


 

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head runat="server">

 

<title>Untitled Page</title>

 

</head>

 

<body>

 

<form id="form1" runat="server">

 

<div>

 

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

 

<asp:UpdatePanelID="up1" runat="server" UpdateMode="Always">

 

<ContentTemplate>

 

            Page Time: <%=DateTime.Now.ToString() %>

 

<asp:Button ID="btn1" runat="server" Text="Click"/>

 

</ContentTemplate>

 

<Triggers>

 

<asp:PostBackTrigger ControlID="btn1"/>

 

</Triggers>

 

</asp:UpdatePanel>

 

 

 

</div>

 

</form>

 

</body>

 

</html>


 

As shown above we have button control in the update panel. Without triggers, for each time we click the button, it displays the current time without page refresh. Whenever we register the PostBackTrigger for button btn1, for each button click page will refresh and displays the current time.


There are two different types of triggers are there.  Those are AsyncPostBackTrigger and PostBackTrigger.Asynchronous post back triggers are used to refresh the page asynchronously and Post back triggers are used to refresh the page normally.

                                                                                                 UpdatepanelTriggersExp.zip (2.99 kb)