Partial Page Updates using ASP.Net AJAX

by top54u.com 10 May, 2008
Spotlight.....

Introduction

AJAX enables the ASP.Net web pages for the Partial-Page rendering to update the content of server controls placed inside the UpdatePanel. AJAX UpdatePanel control separates the controls collection inside it from other controls of the web page. There are some properties of UpdatePanel that controls the asynchronous postbacks that stops the whole page refresh to update the desired content bound to any ASP.Net server control.

 

AJAX UpdatePanel Triggers

UpdatePanel triggers: A collection of trigger events that can cause the UpdatePanel to be updated.

<Triggers>


<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />


</Triggers>

 

Above code displays the AsyncPostBackTrigger associated with the button control with ControlID Button1 and trigger EventName = ”Click”. When associated button control is clicked it causes the asynchronous postback and updates the related UpdatePanel without refreshing the whole web page.

 

AJAX UpdatePanel UpdateMode

UpdatePanel UpdateMode supports 2 values i.e. Always or Conditional
UpdateMode Always causes the UpdatePanel to be updated when any postback event is fired.
UpdateMode Conditional causes the UpdatePanel to be updated only when its associated trigger is fired.

 

Implementing the Partial-Page Updates

To implement the Partial Page Updates with ASP.Net AJAX place 2 UpdatePanel controls on your web page. These UpadatePanel controls will help you to differentiate the content updated visually by asynchronous postbacks without refreshing the whole page. This approach increases the speed of web pages as well as reduces the server load and provides well user experience.

You can download the sample below this article to learn the code for implementing partial page rendering using AJAX UpdatePanel control by just setting the few of its attributes such as UpdateMode and Triggers collection.


HTML code for Partial Page Update

[code:html]
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
       <ContentTemplate>
                        <asp:Label ID="lblTime1" runat="server"></asp:Label>
       </ContentTemplate>
       <Triggers>
          <asp:AsyncPostBackTrigger ControlID="btnTime1" EventName="Click" />
       </Triggers>
</asp:UpdatePanel>


<asp:Button ID="btnTime1" runat="server" Text="Update 1" />
[/code]

 

You can use the similar code for placing the second UpdatePanel. Notice the UpdateMode of above UpdatePanel, also the controlID of AsyncPostBackTrigger associated with button control outside the UdpatePanel.

These settings enable the Partial Page Update by updating only the content of Label control placed inside the above UpatePanel.

Download the sample code here:

ajax partial update.zip (1.36 kb)

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , ,

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

7/24/2008 5:26:45 PM

OUR SPONSORS[+ advertise here]
top54u ezines.....
related videos.....
recent posts.....