I can not seem to get a system timer to work for me. Here is the code both
the aspx and aspx.vb file. The textbox displays "Timer Started" and never
anything else. What am I missing?
<%@ Page Language="VB" Debug="true" AutoEventWireup="false"
CodeFile="test.aspx.vb" Inherits="test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server">This is a text
box</asp:TextBox>
</div>
</form>
</body>
</html>
And the following codebehind file:
Imports System.Web.UI.WebControls
Partial Class test
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not IsPostBack Then
CreateTimer()
Dim myTxt As WebControls.TextBox
myTxt = Form.FindControl("TextBox1")
myTxt.Text = "Timer Started"
End If
End Sub
Private Sub CreateTimer()
Dim Timer1 As New System.Timers.Timer
Timer1.Interval = 5000
Timer1.Enabled = True
AddHandler Timer1.Elapsed, New
System.Timers.ElapsedEventHandler(AddressOf Me.Timer1_elapsed)
End Sub
Private Sub Timer1_elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs)
Dim myText As WebControls.TextBox
myText = Form.FindControl("textbox1")
myText.Text = "Timer Popped " & Today.TimeOfDay.ToString
End Sub
End Class 5 3334
Hello Bill,
This is caused the Timer you define on server side wouldn't worked on
controls on client side. When you execute following code on server:
CreateTimer()
Dim myTxt As WebControls.TextBox
myTxt = Form.FindControl("TextBox1")
myTxt.Text = "Timer Started"
The server will create a new thread to execute code in Timer and run
remained code right away:
Dim myTxt As WebControls.TextBox
myTxt = Form.FindControl("TextBox1")
myTxt.Text = "Timer Started"
Then it sent full response to client. Even the code in the new thread was
finished, it won't send response to client side and the controls on client
won't be updated. In ASP.NET, we cannot use Timer like a Windows Form
application.
Luke
OK, I want change the source of an image at intervals. How do I do that. I
thought a timer would do it.
"Luke Zhang [MSFT]" <lu******@online.microsoft.com> wrote in message
news:Xw*************@TK2MSFTNGXA02.phx.gbl... Hello Bill,
This is caused the Timer you define on server side wouldn't worked on controls on client side. When you execute following code on server:
CreateTimer() Dim myTxt As WebControls.TextBox myTxt = Form.FindControl("TextBox1") myTxt.Text = "Timer Started"
The server will create a new thread to execute code in Timer and run remained code right away:
Dim myTxt As WebControls.TextBox myTxt = Form.FindControl("TextBox1") myTxt.Text = "Timer Started"
Then it sent full response to client. Even the code in the new thread was finished, it won't send response to client side and the controls on client won't be updated. In ASP.NET, we cannot use Timer like a Windows Form application.
Luke
On Wed, 11 Jan 2006 17:58:53 -0600, "Sir Bill"
<Si**************@online.nospam> wrote: I can not seem to get a system timer to work for me. Here is the code both the aspx and aspx.vb file. The textbox displays "Timer Started" and never anything else. What am I missing?
A web page tries to execute as quickly as possible, and then it's done
and gone. It's not like a Windows form, that sticks around, takes user
input, and waits for timers. It is born, it renders, it's gone...
--
Scott http://www.OdeToCode.com/blogs/scott/
A quick and easy solution is a GIF image with multiple frame instead.
Luke This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steve Jorgensen |
last post by:
I know quite well that this question falls into the category of "why does
Access misbehave when I do unexpected things to its objects?", but I thought
I'd ask anyway, and see if anyone knows.
...
|
by: Benny |
last post by:
Hello Experts,
Currently I am working on a windows application using VS.NET 2002 with
C#.
On one of my form, I have a refresh button which will dispose created
controls and re-create them. I...
|
by: J. Hill |
last post by:
I have a Windows Service with a timer but the .Tick event is not being fired/called.
Don't know what code to include...I enabled and started the timer...I have the exact same code in a Windows...
|
by: free2cric |
last post by:
Hi, I intend to use timer whose purpose is to show the current time by
a label on form after specified interval. But it not working . why?
thanks
cric
using System;
using System.Collections;...
|
by: mjheitland |
last post by:
Hi,
I like to know how many threads are used by a Threading.Timer object.
When I create a Threading.Timer object calling a short running method
every 5 seconds I expected to have one additional...
|
by: Rich |
last post by:
Hello,
I am trying to measure the elapsed time between 2
processes. If I declare startTime As Double, endTime as
Double and say
startTime = Timer
....
process1
....
|
by: Steve |
last post by:
I am working on a emulator and need to have time based events. I've tried
to use the timer control and discovered that it runs waaaaaaay slow. I set
the tick frequency to 1, then in the tick...
|
by: appelsinagurk |
last post by:
Hi
I'm fairly new to .Net programming so I'll try to explain my problem as easy as I can, and in advanced sorry for my poor english.
I've got some spare hours where I work, so I've decided to...
|
by: BobAtVandy |
last post by:
I'll greatly appreciate any help on this. Actually 2 questions:
1. I believe I need to use the Windows timer System.Timers.Timer . The
examples I find on the web all access that timer by...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |