Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2006, 12:19 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default Timer Problem

Hello everyone,
I am intending to use timer in one of my webpage of my application(ASP.NET and VB.NET). I want that if user doesn't click on SAVE button within 60 seconds, some event will be raised and he will be redirected to another page. I haven't used timer so someone please guide me how to use it.. What code do I need to write?


Gaurav
__________________
Gaurav
 
Old February 9th, 2006, 09:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You would have your answer already if you typed "ASP.NET Timer" into google.

Try it.


Hal Levy
Please do your own homework.
I am here to help you, not do it for you.
I do not have sample code for anything
 
Old February 9th, 2006, 11:48 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

Yes, I know how to use timer but it is not working. I am writing this code in VB.NET:

Sub Page_Load( ........)
'timer1 is Timer dragged in Design window
timer1.Interval=5000
timer1.enabled=true
End Sub
Sub Timer1_Elapsed(....) Handles Timer1.Elapsed
'textbox1 is a textbox
textbox1.text = "Message"
End Sub

When I run it, Message doesn't display in textbox1 after 5 seconds.
Can anyone tell me where I am wrong in it.

Gaurav.
 
Old February 10th, 2006, 07:40 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

It never will. Web pages are stateless. After your page processes and sends its HTML to the browser, it is long gone.

You'll have to use client-side javascript to do this.

You can tell javascript to do something after a given time using the setTimeout() method:

setTimeout("myTimeoutMethod", 5000); //calls myTimeoutMethod() after 5 seconds.

If you have more questions, please post them in one of the javascript forum areas.

-Peter
 
Old February 11th, 2006, 06:19 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

I dont know how to use JavaScript. Is there no way to do it in VB.NET . The Question I have in my mind is that If we can't use TIMER for this purpose, what is the purpose of it being in .NET environment.
Thank you,

Gaurav
 
Old February 11th, 2006, 01:10 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The timer is a very useful class in .NET. But it's only useful for code that is actually running IN .NET. (Yes, ASP.NET pages are running in .NET but they only run for a brief period of time and are used to create state-less web pages. Once your ASP.NET code runs and generates HTML the code finishes running and no longer has any execution context in which it would utilize an instance of the Timer class.

A fundamental characterist of web applications is that the client's view of the application is simple HTML. The task you are trying to perform requires client side code. This is not the responsibility of the .NET code in an ASP.NET application.

It sounds like you need to review the fundamentals of how web applications behave between the server and client.

-Peter
 
Old February 12th, 2006, 04:37 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

So, It seems to me that we use Timer in .NET for Server-side. To accomplish the task I am intending to do, I will have to use JavaScript code. Thank you Peter. I searched on net and found the code of how to use timer in javascript but I want to know how can I call the VB.NET methods from JavaScript code.. It will be very nice of you if you also tell me any example where we use timer in .NET and what will be the code for it. Thanks again Peter.

Gaurav
 
Old February 13th, 2006, 10:40 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Well, you don't really call the server side methods from javascript, you use javascript to do actions on the form or change the browser URL. You could have javascript "click" a button for you and that button would be a server control button that results in a page postback and a server-side button click event. Or you could just have the javascript change the browser's URL to another page that does what you need.

-Peter
 
Old February 14th, 2006, 11:51 PM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

My requirement is that when certain time elapses, I want to call a method which make a connection to Database and then display something else. In this all I don't want to use any button as this event will be fired automatically after a specified time. After reading your last reply, it seems to me that when this time elapsed I need to redirect to another page where some method will be called and after connecting to database and retrieving the data, I need to redirect again to previous page. Peter tell me if this is the only way to do this task. Or, Is there some other way better than this. Thank you.

Gaurav
 
Old February 16th, 2006, 04:41 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

Can anyone please help me. It will be very nice of you if you help me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Timer problem with Ajax akhilesh_g ASP.NET 2.0 Professional 0 July 31st, 2008 04:11 AM
Problem in Reload a GridView using Timer udhayav .NET Framework 2.0 0 December 16th, 2006 07:16 AM
Timer prasanta2expert Access VBA 1 November 8th, 2006 09:28 AM
System.Threading timer problem for beginner (Windo erikmail C# 2005 1 June 8th, 2006 08:03 AM
timer amerei ASP.NET 1.0 and 1.1 Professional 0 October 15th, 2005 10:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.