473,671 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(se nder, 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.E lapsedEventArgs e). I can trace the code and see
it really go through the route. But it does not work. I added
Page_Load(sende r, e) after the Button_Click. It does not help.

Can somebody give me a clue? Thanks!

Charles
3/11

Mar 11 '06 #1
3 1418
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**********@y ahoo.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.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.Threadin g.Thread.Curren tThread and put it in Page_Load() and
timer1_Elapsed( ) to identify if they are the same thread (by looking at
"DONT_USE_Inter nalThread" 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.P age
{
protected System.Web.UI.W ebControls.Text Box TextBox1;
protected System.Timers.T imer timer1;

private void Page_Load(objec t sender, System.EventArg s e)
{
}
#region Web Form Designer generated code
............... .........
#endregion

private void timer1_Elapsed( object sender,
System.Timers.E lapsedEventArgs 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
4101
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 encode() function behaves differently if a codepage has been set. For example: <script> document.write(escape('Ôèëìè')); (note: that should be five accented characters)
2
1109
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 setting to true when iam going from groupBox2 togroupBox3 example groupBox1 textbox textbox groupBox textbox
3
2559
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 details, their locations, and then add themselves to categories. Each category requires additional info from the suppliers, this additional category info is stored in its own DB table. a suppliers may add themselves to as many categories as required....
6
1117
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 a function and put all the codes inside that and call. But there is additional function call involved in it. My question is can i use delegates to raise the event , If so , How it is done
3
2467
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 error with the Form: Compiler Error Message: CS0122: 'Sonar3.Controls.LoginControl.Button_Click(object, System.EventArgs)' is inaccessible due to its protection level
0
916
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 language = ""javascript"">")) Page.Controls.Add(New LiteralControl("document.location.hash=""expenses""")) Page.Controls.Add(New LiteralControl("</script>"))
2
2232
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 ( http://perla.princeton.edu/counselors/organization.php ) solely for the purpose of showing a bug. It is not production code, it is a test, made for testing, so style really doesn't matter. This page illustrates that, for some reason, clicking on the submit button has a different effect on the...
3
1136
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 specifically from form C (and not form A or B). Is that possible? If so, how? Some more information, form A is in my EXE, form B and C are in a DLL, and the function and sub are in different DLLs than the forms. Darin
17
2667
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 things? Shouldn't they say the same thing?
0
8483
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8824
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8603
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6236
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5703
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2818
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.