Saturday, March 24, 2012

Call function and show results in update panel

Hi,

I've recently dipped into the world of AJAX and want to check if an idea I had is possible with it.

I have a page that takes values passed into from a previous page via a Cross Page PostBack. These values are used in an SQL query on the results page. The problem is that the query is very long, and takes around 5-10 seconds to complete (sometimes longer).

I want to show our users that the page is working in the background, and I believe it can only be done in AJAX. Ideally, I'd like to make a label that says something like "Operation complete" inside an UpdatePanel visible after the SQL query has been completed. I want the rest of the page to complete loading as quickly as possible, and have the update panel display it's message when everything's done.

I can see two ways of doing this:

    Have the SQL query performed on the Page_Load event.Have the SQL query performed directly by the UpdatePanel calling a server side function.

Are either of these methods possible? The first method looks like it should work (maybe with threading), but I'm too much of a novice to know where to start. Can anyone recommend any good tutorials, or show me an example with a simple "Hello World" and Sleep() operation.

By the way, I'm also using master pages.

Thanks for any help you can offer.

Hi,

Please note that on the server side, there is not much difference between handling a normal postback an a partial postback. ASP.NET will create a new instance of the page that being requested to serve the request. And the page will go throught a full lifecycle.
So there won't be much difference between the two ways your posted, but option 2 is a bit better because the operation isn't necessorily to run each time.

I think your problem can be perfectly solved with UpdateProgress Control, please readthis for more information.
Hope this helps.

No comments:

Post a Comment