Code fragment as simple as possible :
public class TestTimer : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l Label1;
protected System.Timers.T imer timer1;
private void Page_Load(
object sender,
System.EventArg s e)
{
Label1.Text = "Before timer";
}
private void timer1_Elapsed(
object sender,
System.Timers.E lapsedEventArgs e)
{
Label1.Text = "After timer";
timer1.Stop();
}
private void InitializeCompo nent()
{
this.timer1 = new System.Timers.T imer();
((System.Compon entModel.ISuppo rtInitialize)
(this.timer1)). BeginInit();
this.timer1.Ena bled = true;
this.timer1.Int erval = 5000;
this.timer1.Ela psed += new
System.Timers.E lapsedEventHand ler(this.timer1 _Elapsed);
this.Load += new System.EventHan dler(this.Page_ Load);
((System.Compon entModel.ISuppo rtInitialize)
(this.timer1)). EndInit();
}
}
When the timer is elapsed, timer1_elapsed method is called
(I see it in the debugger), line
Label1.Text = "After timer";
runs without any problem, but in fact Label1
remains "Before timer" ! WHY ?
Label1 and timer1 were added automatically, with Web form
designer of Visual Studio .Net, InitializeCompo nent()
method was generated automatically, and I did not touch it. 2 1922
The problem is that the timer is a server-side control, and while, yes, it
is firing properly, by the time it fires, the page has already been sent to
the client and therefore, updating the label only updates it on the server.
Once the page has been served, nothing that happens on the server will be
sent down to the client.
If you need something on the client side to update after a given interval,
you might want to look into a javascript timer, they seem to have worked
well for me in the past.
HTH,
-Cliff
"Borr" <an*******@disc ussions.microso ft.com> wrote in message
news:0a******** *************** *****@phx.gbl.. . Code fragment as simple as possible :
public class TestTimer : System.Web.UI.P age { protected System.Web.UI.W ebControls.Labe l Label1; protected System.Timers.T imer timer1;
private void Page_Load( object sender, System.EventArg s e) { Label1.Text = "Before timer"; }
private void timer1_Elapsed( object sender, System.Timers.E lapsedEventArgs e) { Label1.Text = "After timer"; timer1.Stop(); }
private void InitializeCompo nent() { this.timer1 = new System.Timers.T imer(); ((System.Compon entModel.ISuppo rtInitialize) (this.timer1)). BeginInit(); this.timer1.Ena bled = true; this.timer1.Int erval = 5000; this.timer1.Ela psed += new System.Timers.E lapsedEventHand ler(this.timer1 _Elapsed); this.Load += new System.EventHan dler(this.Page_ Load); ((System.Compon entModel.ISuppo rtInitialize) (this.timer1)). EndInit();
}
}
When the timer is elapsed, timer1_elapsed method is called (I see it in the debugger), line
Label1.Text = "After timer";
runs without any problem, but in fact Label1 remains "Before timer" ! WHY ?
Label1 and timer1 were added automatically, with Web form designer of Visual Studio .Net, InitializeCompo nent() method was generated automatically, and I did not touch it.
because the timer fires after the page has been sent to the client, so the
change to label has no impact. you would need to put in a wait for the timer
in your onload, or at least by prerender, for any changes done by the timer
to appear in the rendered page.
-- bruce (sqlwork.com)
"Borr" <an*******@disc ussions.microso ft.com> wrote in message
news:0a******** *************** *****@phx.gbl.. . Code fragment as simple as possible :
public class TestTimer : System.Web.UI.P age { protected System.Web.UI.W ebControls.Labe l Label1; protected System.Timers.T imer timer1;
private void Page_Load( object sender, System.EventArg s e) { Label1.Text = "Before timer"; }
private void timer1_Elapsed( object sender, System.Timers.E lapsedEventArgs e) { Label1.Text = "After timer"; timer1.Stop(); }
private void InitializeCompo nent() { this.timer1 = new System.Timers.T imer(); ((System.Compon entModel.ISuppo rtInitialize) (this.timer1)). BeginInit(); this.timer1.Ena bled = true; this.timer1.Int erval = 5000; this.timer1.Ela psed += new System.Timers.E lapsedEventHand ler(this.timer1 _Elapsed); this.Load += new System.EventHan dler(this.Page_ Load); ((System.Compon entModel.ISuppo rtInitialize) (this.timer1)). EndInit();
}
}
When the timer is elapsed, timer1_elapsed method is called (I see it in the debugger), line
Label1.Text = "After timer";
runs without any problem, but in fact Label1 remains "Before timer" ! WHY ?
Label1 and timer1 were added automatically, with Web form designer of Visual Studio .Net, InitializeCompo nent() method was generated automatically, and I did not touch it. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: codecraig |
last post by:
Hi,
When I do something like.
s = Scale(master)
s.bind("<ENTER>", callback)
def callback(self, event):
print event.type
I see "7" printed out. Where are these constants defined for various
|
by: Henke |
last post by:
Hello,
I have one ImageButton controls which I initialize in
Page_Load and declare on class level.
ImageButton save = new ImageButton();
save.ImageUrl = "save.gif"
save.Click += new ImageClickEventHandler(this.save_click);
This ImageButton is added to a dynamic table which is also
|
by: ProgramAnalyst |
last post by:
Hey all,
I have a label that gets its text from a DB. This text can be changed
on the page in a textbox and after the save button is clicked the new
text is updated in the DB and the page refreshes.
The problem: Even though in the page_load method the label's text is
being set to what is in the DB the text is still the old text. If u
refresh the page the text then updates. Why is this happening? The
label's viewstate is false and if I...
|
by: ibiza |
last post by:
Hi all,
I have a label on a webpage that shows the result of a calculation.
When the page is loaded, the label text is "", and is updated with
javascript via its innerText property. Once I click on a asp:button, I
try to check the value of the label and it is still "" in the button
click event, even tho it had a numeric value when the data was sent.
Is it normal that asp.net does not get the value of a label if it is
changed via...
|
by: ginguene |
last post by:
Its supposed to be a very simple program, with a class to display the
updated current time every second (CAnalogTime) inside a Label in my
form, using ElapsedEventHandler from System.Timers;
The event is working, because the displaybox will show up every second
like requested.
Although the label (which i was able to initialize with a value), wont
update itself in this event.
Any ideas?
| |
by: pallaw |
last post by:
Hello All,
My web Client is using a COM component with connection point enabled.my
client is getting call back from this component.now I have to update a
text control in handler of this callback.but my control is not
updating.can any body tell me how can i update textbox when i get a
thread event .
Thanks & Regards
Pallaw
|
by: =?Utf-8?B?Y2FzaGRlc2ttYWM=?= |
last post by:
Hi,
I have a Label on a Windows form (Version 1.1.4322) and while I iterate
recursively through a method I want to show the name of the current file
being copied to another directory.
The Label is not visible until the backup begins, at which point I resize
the form to show the Label and a ProgressBar. As each file is copied, the
Label is updated:
|
by: hainguyen2x |
last post by:
I'm trying to get a notification from the NT event for any new event
using the DispatchWithEvents() function. Everything seems to be
working the way I wanted, but I don't know how to get the properties
of the event (ie. event type, message, etc.) from the OnObjectReady()
callback.
class SinkClass(object):
def OnObjectReady(self, *args): #self may be the wmi_sink object
print "OnObjectReady callback ..."
print self...
|
by: navyjax2 |
last post by:
What if your event handler has to be nonstatic?
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |