views:

224

answers:

1

Hi folks

I'm working with an UpdatePanel that I'd like to refresh programmatically on the server side. The reason is I display some data that takes a pretty long time to load, so I need to display the page and some sort of progress meanwhile.

What I did is the following, on a page with one UpdatePanel and one ScriptManager:

protected void Page_Load(object sender, EventArgs e)
{
    if(scriptManager.IsInAsyncPostBack)
        testLabel.Text = "AfterUpdate";
    else
        jobsUpdatePanel.Update();
}

This does not what I'd like to do: I'd like the page to be displayed and immediately trigger an asynchronous update of the UpdatePanel in order to load the data - which is what I do instead of assigning another silly text to testLabel.

This is the markup of the UpdatePanel (leaving the ContentTemplete away for the sake of readability):

<asp:UpdatePanel ID="jobsUpdatePanel" UpdateMode="Conditional" ChildrenAsTriggers="true" runat="server">

There is no postback performed at all. Can anybody give me a hint what I'm doing wrong?

Matthias

+2  A: 

You can't push an update from the server to the browser. What the Update method does is to include the contents of the update panel in an AJAX response, so for that to have any effect there has to be a response going back to the browser.

If you want a lengthy process to run on the server and get updates in the browser, you have to start the process in a separate thread, so that the main thread can complete and return the response to the browser. Then the browser can do postbacks or AJAX calls to the server and ask the background thread for the progress status.

Guffa
Well, I've thought about a method to render some client script that immediately posts back - instead of messing with client script on my own, not really pushing updates. :)
Mudu
I added a button with `display: none;` style set and trigger its click event in jQuery. http://api.jquery.com/click/
Mudu