Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update panel updating

Status
Not open for further replies.

darylbewise

Programmer
Jan 5, 2009
16
0
0
GB
Hello all,

Im trying to get an update panel to update while I am executin a large process. If I can output to the screen, I will know exactly where the process is up to. For example:

//.aspx
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="" />
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
        
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="START" />
    </form>
</body>
</html>

//.aspx.cs
Code:
using System;
using System.Threading;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Thread.Sleep(1000);
        Label1.Text = "TEXT1";

        Thread.Sleep(1000);
        Label1.Text = "TEXT2";

        Thread.Sleep(1000);
        Label1.Text = "TEXT3";
    }
}

Im the above example, when Button1 is clicked, the update panel is updated without an actual page refresh. However, when the button is clicked I do not see label1 altering value from "TEXT1" to "TEXT2" to "TEXT3", all that I see is "TEXT3" after a short pause (due to the Thread.Sleep commands.).

Any ideals how I could go about updating the text in Label1 while the code in Button1_Click is still exectuting?

I have even tried to add in "UpdatePanel1.Update();" after setting each Label.Text value, however same happens.

Any help would be much appreciated
 
an request is just that. a single request (ajax or not) so all processing stops for that request until a response is returned. once a response is returned you can do the next thing.

to get the behavior you want you need to issue 3 ajax requests sequentially.
send request A
on success of A send request B
on success of B send request C

the ms ajax client library allows you to code this, but it's not drag/drop like an update panel. i don't have any experience with that js library.

now if each request is long running ajax will make it look pretty, but it will not prevent a timeout error. that is still possible, because all requests are synchronous.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Do you have any examples or websites that I can look at?

Im still a little unclear on how exactly to go about this.
 
that's what google is for.

note: to pull this off you won't be using the drag/drop controls. you will have to write the javascript and server code yourself.

google ms ajax client library or make ajax call with ms ajax client library, or something like that. i'll assume you want to use this library since you are already using the server controls.

i don't have any experience with ms ajax client library. Once i required client scripting I went with jquery and raw html (no more webforms)

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top