473,395 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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

Mar 11 '06 #1
3 1407
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

Mar 13 '06 #2
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" <ch**********@yahoo.com> wrote in message
news:11**********************@i39g2000cwa.googlegr 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

Mar 13 '06 #3
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

Mar 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Scott Matthews | last post by:
I've recently come upon an odd Javascript (and/or browser) behavior, and after hunting around the Web I still can't seem to find an answer. Specifically, I have noticed that the Javascript...
2
by: seash | last post by:
H I have a couple of groupBoxs in my windowsform, these gruopBoxs contains a couple of TextBoxs in them, when i use keyboard 'Tab' key to traverse those Textboxs , groupBox3.ContainsFoucs is not...
3
by: Tim Thomas | last post by:
Hi, I am very new to .NET and am in the process of building my first web application. I will briefly describe what i am trying to achieve: I have a system where suppliers register their...
6
by: thomson | last post by:
Hi all, i have written codes in the button_click event, My problem is that i need to call the same functionality written under the button_click some where else, One thing i can do is i can create...
3
by: I am Sam | last post by:
Please help. I'm dying here and pulling out the last few remaining elements of my hair over this. I have built a form that will identify and authenticate users. I keep getting the following...
0
by: Lars Netzel | last post by:
I have manually written an achor in the HTML mode like this: <a name="expenses"></a> Then at a button_click() I have this code in the code behind: Page.Controls.Add(New LiteralControl("<script...
2
by: ljlolel | last post by:
I'm posting this again because I did not explain myself well the first time, so the problem was not being addressed. I made the following page (...
3
by: Darin | last post by:
I have a program that (for example), has form A that opens form B that opens form C, and form C calls a function, and that function calls a sub. From that last sub, i need to know if came...
17
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/scripts/demo/this-alert.html http://www.frostjedi.com/terra/scripts/demo/this-alert2.html Why, when you click in the black box, do the alert boxes say different...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.