tags:

views:

629

answers:

3

I have a page that dynamically loads multiple user controls on a page. I have a few buttons on each user control that cause a server side event that does some processing related to the user control that triggerred the action.

The problem I run into is that this button click causes the entire page to reload (as all the dynamically loaded controls need to be reloaded on every postback) for all the user controls that makes the page really slow.

Is there a way to tell .NET to ignore the other user controls when a user is interacting with one of the user controls?

All user controls are within updatepanels that have mode set to conditional.

A: 

To answer your question specifically. No. There is no way to "tell .NET to ignore the other user controls". You can, of course, tell your application to ignore things. Perhaps you are missing some if (!Page.IsPostBack) {} statements?

Al W
Well, with dynamically loaded user controls, you will need to load it everytime irrespective of whether it's ispostback or not
Yes, you probably need to load the controls everytime, but is there really nothing in any of the controls that can be skipped if it's posting back and will be handled be a different control?
Al W
+1  A: 

Drop the update panels and switch to using jquery and JSON.

You can focus your code a bit more and should be able to forgo all the control loading crap.

The fundamental problem is that the updatepanels still require the full page to execute in order to send back just the tiny bit of data you want. By moving towards jquery in combination with either page methods or web service methods your page won't have to be reconstituted for each "panel" update.

Chris Lively
Due to technical restrictions, I cannot use web services. Are you saying JQuery can be used to call a method in the code behind?
Yes. It's actually a common pattern. The technical term is "Page Methods" See http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/ to get started
Chris Lively
Also, if you want, the web services don't have to be in a different project. You can have aspx, ashx, and asmx objects in the same visual studio project.
Chris Lively
A: 

You should be able to use UpdatePanels in the scenario you mentioned. There must be something specific to your implementation causing the whole page to refresh. I would suggest stripping it down to isolate the problem. I created the following sample and it worked as expected... only the triggered UpdatePanel was refreshed:

  • Made two user controls that display a new GUID in a Label on each page load.
  • Created a test page with two UpdatePanels. Each UpdatePanel has an empty PlaceHolder control and a button to trigger the async postback.
  • In the Page_Init of the test page, used LoadControl to create instances of the user controls and add them to the respective PlaceHolder (ph.Controls.Add()).

When I click either button inside the UpdatePanel, only that panel refreshes (even though LoadControl is called twice on each async postback to recreate the control hierarchy).

chaiwalla
The problem is I am dynamically adding user controls and it has to be added *everytime* there is a postback. This results in a slow performing page