Tips and Tricks: ASP.NET AJAX 1.0 and User Controls
page 6 of 10
by Bilal Haidar
Feedback
Average Rating: 
Views (Total / Last 10 Days): 51555/ 108

Two UserControls and One UpdatePanel

In this last scenario we will show you how the EmployeeList UserControl, which is now not placed inside an UpdatePanel, will cause a partial-update for the UpdatePanel containing the OrderList UserControl.

In the above two scenarios you noticed that we were using the EmployeeList GridView just to show some data in the OrderList GridView. In this case, there is no need for you to have any kind of AJAX for the EmployeeList. However, if you plan to add some functionalities to the EmployeeList GridView, like editing for example, then it would be a good choice to consider one of the above two scenarios.

In this scenario, the EmployeeList will be placed as it is on the host page with no UpdatePanels and the OrderList will still be placed inside an UpatePanel. Now the question is how will the EmployeeList UsreControl’s event cause a partial-update for the OrderList UserControl?

Well, you have two options to work around it in this case. The first option is to add a Triggers property to the UpdatePanel and specify that the EmployeeList UserControl that has the RowSelected event will cause a partial-update. The other option is simply add the following line of code into the Page_Load event handler of the host page:

Listing 8

protected void Page_Load(object sender, EventArgs e)
{
  this.ScriptManager1.RegisterAsyncPostBackControl(this.EmployeeList1);
}

The RegsiterAsyncPostBackControl method that belongs to the ScriptManager changes the behavior of a server control from causing a postback to causing an asynchronous postback. In this case, the EmployeeList UserControl’s event RowSelected will cause an asynchronous postback. Since this UserControl is not registered as a Trigger to the UpdatePanel, you will have to make the UpdateMode of the UpdatePanel to Always. This way, any server control on the host page causing an asynchronous postback, the UpdatePanel will refresh its content.

If you do not want the UpdatePanel to refresh every time the EmployeeList UserControl’s event RowSelected fires, you can change its UpdateMode to Conditional and add the EmployeeList UserControl with its event RowSelected as a Trigger to the UpdatePanel. This way, the UpdatePanel will refresh its content any time the EmployeeList UserControl’s event RowSelected fires.


View Entire Article

User Comments

Title: very nice   
Name: Serif Emek
Date: 2009-07-28 5:32:09 PM
Comment:
That is just what I was looking for.
Thanks
Title: Re: Vbman   
Name: Bilal Haidar [MVP]
Date: 2008-03-27 10:38:17 AM
Comment:
Hello,
Try to show me the code behind of the usercontrol and how you are setting it on the page!

Thanks
Title: Object reference not set to an instance of an object.   
Name: Vbman
Date: 2008-03-27 10:05:40 AM
Comment:
Great Article!
I have the update panel on the page and the user controls inside the update panel.
I create a property inside the usercontrol that accesses a control, Say the gridviews Tooltip or Pagesize or ...
When I try to set the property on page declaratively I get an error:
Object reference not set to an instance of an object.

I've seen this problem posted in other places but no solution.
Have you run into this and do you have a work around.

Thanks!
Title: Re:   
Name: Bilal Haidar
Date: 2007-10-30 10:43:12 AM
Comment:
Hello,
You can use this converter:
http://bhaidar.net/cs/archive/2007/04/18/telerik-c-vb-net-converter.aspx

Regards
Title: VB.Net   
Name: Jo
Date: 2007-10-30 5:51:05 AM
Comment:
Article is so good. If it is available in vb.net also it will be helpful for the beginners.
Title: Well explained   
Name: Jose
Date: 2007-08-09 4:44:16 AM
Comment:
As usual, you did a great job!

I loved the fact that you showed all the possible combinations you can have with a gridview user control and AJAX. And the sample works really fine!

Jose
Title: Great   
Name: Mark W
Date: 2007-06-25 9:24:07 PM
Comment:
Very well summarized, thanks. I agree, good use of events and generics.

Also, there's a small typo in Listing 5: OrderList UC's UpdatePanel ID should be 'AjaxPanel'.
Title: Nice one   
Name: Wesley Bakker
Date: 2007-06-24 4:32:51 AM
Comment:
Nice article. Decent use of events, AJAX, generics, datasourcecontrols etc. etc.

Cheers,
Wes






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-28 11:04:19 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search