Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Why calling Button_Click() behaves differently from really clicking the button?

Reply
Thread Tools

Why calling Button_Click() behaves differently from really clicking the button?

 
 
charles
Guest
Posts: n/a
 
      03-11-2006
Hi:

In my page I need to re-start a thread. I put the code into a
Button_Click(sender, e) handler. When I click the button, it works.
Then I call this handler inside a timer's handler timer1_Elapsed(object
sender, System.Timers.ElapsedEventArgs e). I can trace the code and see
it really go through the route. But it does not work. I added
Page_Load(sender, e) after the Button_Click. It does not help.

Can somebody give me a clue? Thanks!

Charles
3/11

 
Reply With Quote
 
 
 
 
charles
Guest
Posts: n/a
 
      03-13-2006
I discovered that timer1_Elapsed() is in a different thread than the
main page thread, while Button_Click() is in the main thread. Maybe
that is the reason.

I don't know how to handle the thread to automate Button_Click() so
that no human intervention is needed. Please help.

Charles
3/13

 
Reply With Quote
 
 
 
 
Bruce Barker
Guest
Posts: n/a
 
      03-13-2006
its the same thread, but the request has completed (rendered html sent back
to browser). in fact by the time the timer fires, the thread may be
processing the next request. you need to put a wait in your page (say in
prerender) for your background thread to compelete, if it needs to update
the rendered html.


-- bruce (sqlwork.com)






"charles" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>I discovered that timer1_Elapsed() is in a different thread than the
> main page thread, while Button_Click() is in the main thread. Maybe
> that is the reason.
>
> I don't know how to handle the thread to automate Button_Click() so
> that no human intervention is needed. Please help.
>
> Charles
> 3/13
>



 
Reply With Quote
 
charles
Guest
Posts: n/a
 
      03-15-2006
Dear Bruce:

Please teach me how to write in prerender in order to wait for the
background thread to complete.

I don't quite understand your answer. I used a statement aThread =
System.Threading.Thread.CurrentThread and put it in Page_Load() and
timer1_Elapsed() to identify if they are the same thread (by looking at
"DONT_USE_InternalThread" value, which is a unique int for each thread.
Is this the right way?). I found that their values are different.

What is the "background thread" you referred to?

Below is the simple code I used for testing: (The text never showed
up.)

================================================== ========
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Timers.Timer timer1;

private void Page_Load(object sender, System.EventArgs e)
{
}
#region Web Form Designer generated code
........................
#endregion

private void timer1_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
TextBox1.Text = "Here!";
}
}
================================================== =========

Thanks a lot!

Charles
3/15

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Why this method behaves differently? otsarri Java 3 09-11-2004 03:30 PM
ASP.NET behaves differently when loading our assembly Simon Kennedy ASP .Net 0 01-30-2004 06:02 AM
same web page behaves differently on servers Do ASP .Net 1 11-16-2003 08:11 AM
JLabel behaves differently printing than in GUI Cindy Huyser Java 1 08-07-2003 09:53 PM



Advertisments