Wednesday, August 18, 2010

How to add timer on code behind file which redirect to another page after 10 secs? ASP.NET?

I am new to the asp.net with vb...i want to use timer for displaying some message on page for some time and then the page should automatically redirected to the another page using params in querystring... thanksHow to add timer on code behind file which redirect to another page after 10 secs? ASP.NET?
i can think of two ways, one with meta refresh tag, and another with simple javascript.


First one, with meta tag; put this in your head section of page:


%26lt;meta http-equiv=';refresh'; content=';15;url=http://example.com/';/%26gt;





Second one, with javascript block can look like this:


%26lt;script%26gt;


setTimeout(


function() { window.location=';http://www.google.com';; },


15000


);


%26lt;/script%26gt;





Both scripts redirect after 15 seconds. With second one, you can create URL string with params. If you want to inject something user entered in TextBox, then you use inline vb.net (this is js inside aspx):


var element=document.getElementByID('%26lt;%= TextBox1.ClientID %%26gt;');


var url=';www.google.com?query=';+element.valu鈥?br>

(all this put inside function() )





hope it helps!

No comments:

Post a Comment