ARTICLE

UpdatePanel control in ASP.NET AJAX

Posted by Rohatash Kumar Articles | ASP.NET AJAX in VB.NET November 24, 2010
In this article we will learn how to use UpdatePanel control in ASP.NET AJAX.
 
Reader Level:

In this article we will learn how to use updatePanel control in ASP.NET Ajax.

UpdatePanel Control

UpdatePanel control is used with ScriptManager control to enable partial rendering of the page. You must be aware that partial page rendering reduces the need for synchronous postbacks and complete page updates when a part of the page need to be updated.

ContentTemplate

ContentTemplate tag is used inside the updatepanel and all the contents within the <contentTemplate> tag alone will be updated during the partial page update.

Properties

up2.gif

Figure 1.

Triggers - A collection of triggers that can be cause the UpdatePanel to be updated.

UpdateMode - Indicates weather the UpdatePanel will refresh on every asynchronous postback or only as the result of specific action.

ClientIDMode -Indicates how the client id should be generated for the control.

For example:

Drag a Updatepanel control, ScriptManager control, one button control, and a label control from the toolbox on the form.

up1.gif

Figure 2.

Now when we click on the button, then we will see the label get a new number each time. Notice the wonderful absence of a blinking window and a running status bar.

Now click on the source button from design window.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

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

<head runat="server">

    <title></title>

</head>

<body>

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

    <div>

   

        <br />

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

        </asp:ScriptManager>

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">

       

    <ContentTemplate >

        <asp:Button ID="Button1" runat="server" Text="Update" />

        <br />

        <br />

        <br />

        <br />

        <asp:Label ID="Label1" runat="server" Text="[Label]"></asp:Label>

        </ContentTemplate>

    </asp:UpdatePanel>

    </div>

    </form>

</body>

</html>

 

 

Now double click on the button and add the following code.

 

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        Label1.Text = "Random Number : " & New Random().Next().ToString()

    End Sub

 

Now save and run the application.


up3.gif 

Figure 3.

 

The above figure displays when we click on the button repeatedly the page will not refresh and label generates different random number.

 

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Team Foundation Server Hosting
Become a Sponsor