Handling Event To Cause A PostBack

D

dave_wurtz

All,

First a little information...
I have a class library that was developed for a GUI application that I
am trying to get to work on my ASP.NET application. The library
essentially is used to query a SQL database. It build the SQL Select
statement based on specified criteria and submits it to the database.
The statement is run on its own thread and when results are returned,
it fires an event, passing a dataset of information as one of the
parameters. In a GUI app, I simply handle the event and display the
results of the dataset.

Here's my problem...
I have a button on my ASP.NET form that instantiates the query class,
defines the criteria, and calls execute (method off the query class).
Because the execute is run on its own worker thread, execution
continues and the button thinks it is done. It appears to be executing
a postback as I see the page be "refreshed". However, when the
query.Execute is done, an event gets fired, which I am handling in a
method that assigns the dataset to a datagrid and I call databind. The
grid, however, is never displayed. It appears that a postback or
something is needed to refresh the page. How can I get this to work?

I am new to ASP.NET development so I hope this makes sense.

Your help is appreciated!

Dave Wurtz
 
D

dave_wurtz

Eliyahu,

Thank you for responding.

That's what I thought was going on. Thank you for confirming.

The query class is already built and runs on its own thread. I'm just
trying to reference this class rather than "reinventing the wheel".
There are other beneficial reasons to put this on its own thread but,
like you said, this is for another topic.

When you say "There is no page anymore", what do you mean. Pardon me
if that is a basic question, but I don't fully understand what you
mean. Is there a different approach that I should take here to get my
datagrid populated (other than rewriting my query class)?

Thanks again for looking at this!

Dave
 
R

Rosanne

This is how we force a post back to get the page to refresh:

Add a subroutine in the code behind the page:
'Build dynamic script to force a postback to the page
Private Sub ForcePostBack()
Dim strRedirectBuilder As StringBuilder = New StringBuilder

strRedirectBuilder.Append("<script language='vbscript'>")
strRedirectBuilder.Append("ForceRedirect")
strRedirectBuilder.Append("</script>")

Page.RegisterStartupScript("Redirect"
strRedirectBuilder.ToString)
End Sub

Then in the script you will need the 'ForecRedirect' routine:
public sub ForceRedirect(strWOID)
dim strPath
strPath = "PageName.aspx"
window.navigate(strPath)
end sub


Hope this helps
 
E

Eliyahu Goldin

Dave,

The following scenario is taking place:

The page starts the thread, the button thinks it is done, the page completes
building the http response, sends it to the client and ceases to exist.
After a while your thread is really done with the dataset and offers it to
the page. Oops, here is the problem. There is no page anymore.

You don't gain anything by building the dataset in a thread. Unless you want
to provide a sort of asynchronous processing where the user gets the
response before the dataset is ready and then picks it up later. But that is
already another story.

Eliyahu
 
E

Eliyahu Goldin

Dave,

You can keep the query class as it is. After the button starts it, it should
sit and wait till it's done. Make a sort of loop checking the thread status.
When the dataset is ready, databind the grid to it.

All your controls, including the datagrid, reside in the page object. That's
what an .aspx file is all about. "There is no page anymore" means there is
no object representing the page in the server's memory anymore. There are
numerous sources for "asp.net page life cycle". Google for one.

Eliyahu
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top