Asynchronous Callback Not Updating Web Page???

T

TC

Hello,

I am making an asynchronous call to a webservice and trying to update the
web page with the results.

The page is not updating.

Does anybody know why???

Below is my code:

public class ASPNetSuperhero : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList drplstFilePaths;
protected System.Web.UI.WebControls.TextBox txtMessage;
protected System.Web.UI.WebControls.Button btnStartFileSearch;

private localhost.ASPNetSuperheroService GetWordCount;
protected System.Web.UI.WebControls.Label lblWordCount;
private AsyncCallback MyWordCountCallback;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnStartFileSearch.Click += new
System.EventHandler(this.btnStartFileSearch_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnStartFileSearch_Click(object sender, System.EventArgs e)
{
MyWordCountCallback = new AsyncCallback(WordCountCallback);
/* Create new instance of the webservice that provides
the required functionality*/
GetWordCount=new localhost.ASPNetSuperheroService();
GetWordCount.BeginWordCount(MyWordCountCallback,GetWordCount);
}

private void WordCountCallback(IAsyncResult Result)
{
// Call the webservice method in order to get current word count
this.txtMessage.Text=GetWordCount.EndWordCount(Result);
}
}


Regards,

TC
 
T

TC

Hey folks,

I need C# assistance for non-blocking, asynch callback from the web page.

I am currently receiving the appropriate values back but the page does not
update.

Does anyone know why?

Regards,

TC
 
M

[MSFT]

Hello,

ASP.NET application uses request/response architecture, and it may not be
suitable for asynchronous call to a web service. Regarding your code:

private void btnStartFileSearch_Click(object sender, System.EventArgs e)
{
MyWordCountCallback = new AsyncCallback(WordCountCallback);
/* Create new instance of the webservice that provides
the required functionality*/
GetWordCount=new localhost.ASPNetSuperheroService();
GetWordCount.BeginWordCount(MyWordCountCallback,GetWordCount);
}

After BeginWordCount, the response will be write back to client, won't wait
here. You have to use synchronous call here.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
P

Patrice

You initiate the call but don't wait for the result. The goal of an
asynchornous call is for example :
- make the call to a web service
- do some work
- get the result (will still wait if not already available)

That way you can do some work in parallel.

If you need the result from the webservice and you have nothing to do in
between making an asynchronous call is useless.

Patrice
 
T

TC

Actually, the idea would be to free up the GUI so that a user isn't stuck.
That makes an asynch call very useful. Then the user can do whatever work
they wish to and when the webservice returns the appropriate information,
the application can finish the work behind the scenes.

At least this is what I am trying to do.

Todd
 
J

John Saunders

TC said:
Hello,

I am making an asynchronous call to a webservice and trying to update the
web page with the results.

The page is not updating.

Does anybody know why???

Yes. Your page does not exist when your callback is called.
private void WordCountCallback(IAsyncResult Result)
{
// Call the webservice method in order to get current word count
this.txtMessage.Text=GetWordCount.EndWordCount(Result);
}
}

When this method is called back, the request has already completed, the
response has already been sent to the client, and you are out of luck.

I recommend that you find some sample code which does this and follow that
example. I can recommend it because you're not going to find any such sample
code - the entire idea is contrary to the way that ASP.NET works.

See
http://msdn.microsoft.com/library/d...on/html/vbconwebformspageprocessingstages.asp.
 
P

Patrice

Humm. Sorry if I restate something ovbious...

The page the user sees is just some HTML that is rendered by the server side
APSX page. Once the ASPX page is finished the user see client side HTML code
and the page doesn't exist any more server side. You nedd then another HTTP
request to be in touch again with server side code.

I see basically two options :

- you need the webservice call to be completed to have a meaningfull page :
- out of luck, needs to wait the result from the webservice to construct
the final HTML page
- use an IFRAME that calls an ASPX page that calls this webservice. The
user can see a part of the final UI (done by the main ASPX page) but will
have still to wait a bit to see the inner frame content(done be the ASPX
page referenced by the IFRAME). Of course, if the webservice is quite
qucik,, the first optino is probably still the simpler.

- you don't need the webservice call to be completed (will be used sometimes
later)
- you could queue these calls to have them done seperately from the user
page (AFAIK .NET proivides something along these lines was called MSMQ
previously)

Do you recognize a case in which you are ?

Patrice
 
T

TC

Hey Folks,

Thanks for the help!

Basically, because what I wish to do is contrary to the way in which ASP
works, I'm just gonna wait for the response to return.

Thanks Again,

TC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top