Wednesday, March 21, 2012

loading web user controls asynchronously

I am new to asp.net ajax. I want to load multiple web user controls in a aspx page independently after the page has been loaded so that user will know that something is happening in the page rather than showing them blank screen. IS there a way to do it using Ajax or is it not possible to do so?

any help would be appreciated

You could have update panel for each user control that have a timer set as their trigger. When the timer elapses, load the user control you want into each update panel. use an update animation in each to let the user know something is happening.


This seems a bit backwards. UserControls become a part of the page itself, so delaying their "loading" isn't likely to help you. If you want to show some sort of progress or other indicator to the user while the page is processing, you can do that with an animated gif or with Remote Scripting ("AJAX").


how can i achieve remote scripting using asp.net ajax. The problem is i have couple user controls that runs heavily in database and it takes about 5 seconds to finish. I want to display the remaining content in the page while the user control is loading.

please help.


hello.

well, the only option i see is to laod the page without that content and then call a web service from the client side that gets the data from the server and presents them to the user. you should keep in mind that an asp.net page generates html that is sent back to the client. this means that you cannot sent the page to the client with "wholes" that will be filled up later...it simply doesn't work like that!


It's true you can't leave holes in the HTML, but that doesn't mean you need load everything at one time.

If you modify your user control to not load the data that takes five minutes on page load, but only to load it when a certain method is run you can load the user controls in the update panels as I suggest above and then you can trigger the data to be loaded into it via a timer, or a java script function that runs when the page loads in the client's browser.


hello again.

true, but in those cases, why not simply call a web service and then use js to update the ui without incurring in another partial postback?


If you do that can you use the updatePanel animation to notify the user that something is happening or do you have do it manually with js?


hello.

well, the updateprogress is really a wrapper around client behavior that is responsible for showing/hiding the contents you define. the upadteprogress is "tied up" with the partial postback model based on the server side approach.

nothing prevents you from doing something like this is js:

1. define the wait msg in an html element that has its display style set to no none

2. start the web service call and change the display of the element defined on 1

~3. handle the cb and error cb methods and make sure that you set the style of the element defined on 1 to none

yes, you do have to write some js code, but when you think about it, the J in AJAX stands for Javascript, right? :)


i am thinking to call the update panel after onload event using javascript. is there any idea how to call update panel using javascript.


hello.

well, the easiest way i've seen is to call __doPostBack and pass it the client id of the panel you want to update:

http://encosia.com/2007/07/13/easily-refresh-an-updatepanel-using-javascript/


I just came accross a post where xr280xr says he acomplished exactly what you're trying to do using a timer.http://forums.asp.net/t/1176152.aspx


well, i'm sure that the timer has its uses, but if you just want to refresh the panel after the page has been loaded through js code, the link i've mentioned is the best option.


I'm happy to defer to your increased experience and knowledge on this, but can you explain why it would be preferable to go through the hassle of manually writing a JS function to do it as opposed to just using the timer as described in that post. I truly don't mean this in a rude way; I just don't see the benefit. Could you explain?


Luis,the link you provided is not working. would you please provide again.

No comments:

Post a Comment