Update Panel in ASP.Net

UpdatePanel (AJAX Control)

The UpdatePanel is an important control in the ASP.NET AJAX package. It will prevent the refreshing of the entire page, while changes happening in the controls contained within it, allowing partial rendering of the area. The update panel is always associated with a Script Manager on the page .

The <asp:UpdatePanel> tag has two childtags – the ContentTemplate and the Triggers tags. The ContentTemplate tag is required, since it holds the content of the panel. The content can be anything that you would normally put on your page, from literal text to web controls. The Triggers tag allows you to define certain triggers which will make the panel update it’s content. The following example will show the use of both childtags.

<body>
    <form id=”form1″ runat=”server”>
        <asp:ScriptManager ID=”ScriptManager1″ runat=”server” />
        <asp:UpdatePanel runat=”server” id=”UpdatePanel” updatemode=”Conditional”>

        <Triggers>
            <asp:AsyncPostBackTrigger controlid=”UpdateButton” eventname=”Click” />
        </Triggers>

            <ContentTemplate>
                <asp:Label runat=”server” id=”DateTimeLabel1″ />   
            </ContentTemplate>
     </asp:UpdatePanel>
                <asp:Button runat=”server” id=”UpdateButton” onclick=”UpdateButton_Click” text=”Update” />

    </form>
</body>

Here is the CodeBehind. Just add the following method to the file:
protected void UpdateButton_Click(object sender, EventArgs e)
{
    DateTimeLabel1.Text = DateTime.Now.ToString();
 }

Read more from MSDN

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s