This tutorial will explore Partial Page Updates with ASP.NET AJAX. C#


V4 Ajax Tutorials
Server Intellect Cloud Hosting

This tutorial will explore Partial Page Updates with ASP.NET AJAX. C#

This tutorial will explore Partial Page Updates with ASP.NET AJAX. C#

In this tutorial we will explore ASP.NET AJAX Extensions ability to do a partial or incremental page update without doing full postbacks to the server, without any code changes and with minimal markup changes.

The ability to integrate partial page rendering is integrated into ASP.NET with small changes to your project. Let’s start by integrating partial rendering into an existing project. Assuming that you have Visual Studio 2008 you can start.

Need help with Windows Dedicated Hosting? Try Server Intellect I'm a happy customer!

To begin, start Visual Studio 2008, and create a new page by clicking File > New > Web Site > ASP.NET and name it AjaxPPRender or whatever you would like. Now you are in front of a blank default.aspx page with basic markup. First, drag and drop a Label control (lblLabel), and a Button control (btnButton) onto the page with the form element.

Set the Label text properties to “Congradulations! You have clicked the Button!” and the Button text to “Click”. Now navigate to the code behind view or double click the btnButton to generate the button handler. Then set the lblLabel.Text to “Congradulations! You have clicked the Button!”. The default.aspx markup should look similar to example below:

<body>
    <form id="form1" runat="server">
      <div>
        <asp:Label ID="lblLabel" runat="server" Text="This is a label!">
        <asp:Button ID="btnButton" runat="server" Text="Click Me" OnClick="btnButton_Click" />
     </div>
   </form>
</body> 

If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!

The default.aspx.cs page should look similar to this example below:

protected void btnButton_Click(object sender, EventArgs e)
{
lblLabel.Text ="Congradulations! You have clicked the button!"
}

Now you can Save and Run and Test. Click the button and notice how the page refreshes to change the text in the label, or if there is a little flicker as the page is redrawn. Close your browser window and return to Visual Studio and navigate to “AJAX Extensions”.

Next, create some whitespace before the lblLabel and as shown above locate the UpdatePanel within the AJAX Extensions and place it there or you can do so by doing the following to your default.aspx markup:

<asp:UpdatePanel ID="upUpdatePanel" runat="server">
    <ContentTemplate>
       <asp:ScriptManager ID="smScriptManager" EnablePartialRendering="true" runat="server">
       </asp:ScriptManager>
       <asp:Label ID="lblLabel" runat="server" Text="Label">
       </asp:Label>
    </ContentTemplate>
</asp:UpdatePanel> 

**Important: Either way drag or type in the closing tag past the end of the button element so that the lblLabel and btnButton controls are wrapped. Then after that tag, open a new tag called .. This tag should wrap around the lblLabel and btnButton tag as well.

Anywhere within the element inlcude a ScriptManager control by simply double clicking it in the toolbox. After you place that tag in change include the attribute EnablePartialRendering=”true”.

<form>
<br />
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
      <title>Integrating Partial Page Rendering </head>
 <body>
  <form id="myForm" runat="server">
    <div>
       <asp:UpdatePanel ID="upUpdatePanel" runat="server">
         <contentTemplate>
    </div>
       <asp:ScriptManager ID="smScriptManager" EnablePartialRendering="true" runat="server">
       </asp:ScriptManager>
       <asp:Label ID="lblLabel" runat="server" Text="Label">
     <br />
       <asp:Button ID="btnButton" runat="server" onclick="btnButton_Click" Text="Click" />
       </ContentTemplate>
      </asp:UpdatePanel>
   </form>
  </body>
 </html>

Notice if you open your web.config file you should notcie that Visual Studio has automatically added a complilation reference to System.Web.Extensions.dll. Now if you run your Web site you can notice how no source code changes were required to support partial page rendering; only the markup was changed.

We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!

Notes:

The ScriptManager control is a very important control within the ASP.NET AJAX Extensions. It provides access to the script library, supports partial rendering, and provides extensive support for additional ASP.NET services. Some of those services include authentication and profiling. It also provides globalization and localization support for the client scripts.

Learn How to Handle Custom Errors for UpdatePanels

 We will quickly go over how to handle custom errors for UpdatePanels. Despite that updates are handled by triggers determined by UpdatePanel controls, the support for error and custom error handling messages is by a page’s ScriptManager control instance. By exposing an event, AsyncPostBackError, to the page can appropriately provide custom exception handling logic.

When applying a AsyncPostBackError event, specify the AsyncPostBackErrorMessage property, which will then prompt an alert box to be raised upon completion of the callback. Also, client side customization is also possible instead of the default alert box. For example, if you want to display a customized element rather than box. In a case like that you might handle the error like this example below:

<script type=”text/javascript”>

The code script above registers a callback with the client side AJAX runtime after the asynchronous request has been complete. Then it checks for an error, if so, processes, then indicates to the runtime that the error was handled in a custom script.

We moved our Web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 


Comments
clothing websites said:

It’s quite hard to find a good website. And I am very satisfied to have come here. The publications are doing great and full of good insights. I would be glad to keep on coming back here to check for a new update.

Posted Dec 1, 2010 10:25 AM
Camouflage wedding dresses said:

Will this tutorial explores Partial Page Updates with ASP.NET AJAX. C # Thanks. Maybe the price should be balanced with gov intervention,. The invisible hand "formula" doesn't work all the time.

Posted Feb 2, 2011 12:34 PM
Men's Suits said:

This tutorial is very informative and easy to follow. Thanks for sharing it with us.

Posted Feb 14, 2011 7:36 AM
cherche viagra said:

The layout for your web site is a bit off in OmniWeb. However I like your blog. I may have to install a normal browser just to enjoy it

Posted Mar 9, 2011 5:09 PM
San Diego Attorney said:

I was in a great problem with Partial Page Updates with ASP.NET AJAX. C#. I could not solve the problem though I was trying again and again.By this blog now I have learned to get rid of this problem.I am grateful to your blog.Thank you very much.

Posted May 28, 2011 3:39 AM
Cedar Park Roofing Contractors said:

This is an straightforward mortgage to obtain for almost any form of credit. You are going to start out off by filling out a short software answering concerns about your revenue, your age, your handle, and also a number of other points.

Posted Jun 26, 2011 5:50 AM
Brazos Place Condos for Sale said:

The flexibility of Enterprise Value Architect (EVA) and the Graphical Modeler allowed us to quickly and easily add the necessary meta model elements and define the notations required.

Posted Jun 26, 2011 5:39 PM
homeowners association website said:

Hello, you used to write great post, but the last few posts have been kinda boring.. I miss your tremendous posts. Past few posts are just a little bit out of track!

Posted Jul 17, 2011 3:41 AM
trace cell said:

good to come across a blog every once in a while that isn't the same unwanted rehashed information. Wonderful read!

Posted Jul 21, 2011 9:33 AM
achat prevacid en ligne said:

A code very interesting.

Posted Aug 3, 2011 11:12 AM
www.outlet-louisvuitton.us said:

www.outlet-louisvuitton.us

Posted Aug 6, 2011 3:36 AM
viagra kopen zonder recept said:

Thanks a lot for posting this one here. It's the first time when I spotted that article like that in some website that I didn't know before. I will definitely bookmark your blog and keep an eye on it in the future too. Thanks!

Posted Aug 29, 2011 11:47 AM
running gear said:

Its very nice site. i have read lot of wonderful things here and entertaining too.i am very thankful to you because here i can remove my reading and knowledge thirst.please keep posting

Posted Oct 11, 2011 11:38 AM

Leave a Comment