Asynchronous WebService Callback to Force Postback


G

Guest

Hello,

I have an ASP.Net webform that shows numerous attributes of parts we sell.
There is one portion of the form that I have the user click a button to get
the information for. I did this for two reasons: 1) not everyone wants to
see it every time. 2) Depending on the complexity of the part, it can take a
while.

Everything works great. However, on complex parts (say that return 10,000 +
lines) the browser says it is "Not Responding" but I know I just have to
wait. I then did some research and it sounds as if I make an Asynchronous
call to the WebService method, I would not get the Not Responding issue.

So here is my code when they click the button to get the information...

private void Button1_Click(object sender, System.EventArgs e) {
dgrdBOM.Visible = true;
AsyncCallback cb = new AsyncCallback(this.QueryCallback);
IAsyncResult ar = oWS.BeginGetItemBOM(iUniqueID, iOrganizationID, 1,
cb, oWS);
lablTest.Text = "Kevin";
}

I threw the lablTest in there to make sure it at least gets that far and it
does. Here is the callback function.

public void QueryCallback(IAsyncResult ar) {
PartExplorerWS.PartInfo oWS2 = (PartExplorerWS.PartInfo) ar.AsyncState;
DataSet dsResults;

lablTest.Text = "Here";
dsResults = oWS2.EndGetItemBOM(ar);
dgrdBOM.DataSource = dsResults;
dgrdBOM.DataBind();
dgrdBOM.Visible = true;
}

I never get the lablTest to update to "Here" The specific query I am
running should only take about 1-2 seconds in this test case. Am I missing
something?

TIA,
Grigs
 
Ad

Advertisements

B

bruce barker

your approach will not work. here is your flow

browser ->> requests page

webform
onload page
starts asyn webcall
<<--- returns page response
browser renders page

<<-- async call finshes
update form data in server memory.


unless the asyn call finishes before the page response is sent to the
browser, the browser never sees the results. you need to wait on the async
call in the prerender event, but this may defeat the purpose of the async
call.

you should start a background thread to do the query, then have the page
poll for the result.

-- bruce (sqlwork.com)


| Hello,
|
| I have an ASP.Net webform that shows numerous attributes of parts we sell.
| There is one portion of the form that I have the user click a button to
get
| the information for. I did this for two reasons: 1) not everyone wants
to
| see it every time. 2) Depending on the complexity of the part, it can
take a
| while.
|
| Everything works great. However, on complex parts (say that return 10,000
+
| lines) the browser says it is "Not Responding" but I know I just have to
| wait. I then did some research and it sounds as if I make an Asynchronous
| call to the WebService method, I would not get the Not Responding issue.
|
| So here is my code when they click the button to get the information...
|
| private void Button1_Click(object sender, System.EventArgs e) {
| dgrdBOM.Visible = true;
| AsyncCallback cb = new AsyncCallback(this.QueryCallback);
| IAsyncResult ar = oWS.BeginGetItemBOM(iUniqueID, iOrganizationID, 1,
| cb, oWS);
| lablTest.Text = "Kevin";
| }
|
| I threw the lablTest in there to make sure it at least gets that far and
it
| does. Here is the callback function.
|
| public void QueryCallback(IAsyncResult ar) {
| PartExplorerWS.PartInfo oWS2 = (PartExplorerWS.PartInfo)
ar.AsyncState;
| DataSet dsResults;
|
| lablTest.Text = "Here";
| dsResults = oWS2.EndGetItemBOM(ar);
| dgrdBOM.DataSource = dsResults;
| dgrdBOM.DataBind();
| dgrdBOM.Visible = true;
| }
|
| I never get the lablTest to update to "Here" The specific query I am
| running should only take about 1-2 seconds in this test case. Am I
missing
| something?
|
| TIA,
| Grigs
 
G

Guest

That makes sense. Thank you.

So, do you have an example of your thread suggestion?

Grigs
 
Ad

Advertisements

B

bruce barker

google this newsgroup on progress bar - its the same problem.

-- bruce (sqlwork.com)

| That makes sense. Thank you.
|
| So, do you have an example of your thread suggestion?
|
| Grigs
|
| "bruce barker" wrote:
|
| > your approach will not work. here is your flow
| >
| > browser ->> requests page
| >
| > webform
| > onload page
| > starts asyn webcall
| > <<--- returns page response
| > browser renders page
| >
| > <<-- async call finshes
| > update form data in server memory.
| >
| >
| > unless the asyn call finishes before the page response is sent to the
| > browser, the browser never sees the results. you need to wait on the
async
| > call in the prerender event, but this may defeat the purpose of the
async
| > call.
| >
| > you should start a background thread to do the query, then have the page
| > poll for the result.
| >
| > -- bruce (sqlwork.com)
| >
| >
| > | > | Hello,
| > |
| > | I have an ASP.Net webform that shows numerous attributes of parts we
sell.
| > | There is one portion of the form that I have the user click a button
to
| > get
| > | the information for. I did this for two reasons: 1) not everyone
wants
| > to
| > | see it every time. 2) Depending on the complexity of the part, it can
| > take a
| > | while.
| > |
| > | Everything works great. However, on complex parts (say that return
10,000
| > +
| > | lines) the browser says it is "Not Responding" but I know I just have
to
| > | wait. I then did some research and it sounds as if I make an
Asynchronous
| > | call to the WebService method, I would not get the Not Responding
issue.
| > |
| > | So here is my code when they click the button to get the
information...
| > |
| > | private void Button1_Click(object sender, System.EventArgs e) {
| > | dgrdBOM.Visible = true;
| > | AsyncCallback cb = new AsyncCallback(this.QueryCallback);
| > | IAsyncResult ar = oWS.BeginGetItemBOM(iUniqueID,
iOrganizationID, 1,
| > | cb, oWS);
| > | lablTest.Text = "Kevin";
| > | }
| > |
| > | I threw the lablTest in there to make sure it at least gets that far
and
| > it
| > | does. Here is the callback function.
| > |
| > | public void QueryCallback(IAsyncResult ar) {
| > | PartExplorerWS.PartInfo oWS2 = (PartExplorerWS.PartInfo)
| > ar.AsyncState;
| > | DataSet dsResults;
| > |
| > | lablTest.Text = "Here";
| > | dsResults = oWS2.EndGetItemBOM(ar);
| > | dgrdBOM.DataSource = dsResults;
| > | dgrdBOM.DataBind();
| > | dgrdBOM.Visible = true;
| > | }
| > |
| > | I never get the lablTest to update to "Here" The specific query I am
| > | running should only take about 1-2 seconds in this test case. Am I
| > missing
| > | something?
| > |
| > | TIA,
| > | Grigs
| >
| >
| >
 

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

Top