Auto-redirect via code behind

How am be able to redirect a page after 5 seconds through code behind file?
I cannot simply type


But is it possible if I’m going to do it through meta tag even if my page is under a master page file?

If you want to achieve a delay in you app, in the code-behind, add this before the redirect:


…to delay for 5 sec. Javascript implements the same technique. When that code is executed, your program will be halted, before moving to the next line of code.

Hope it helps.

but, I read a while back that using System.Threading.Thread.Sleep(5000) will sleep the server. Let me read again later.

I think he’s talking about a delay on the client-side.

To that end, you don’t need to fiddle with the meta tags, just use normal HTML DOM objects to load a new page with the setTimeout() method.


settimeout? but I don’t have a body tag…because the page is under a masterpage.

You can inject script tags anywhere into the page. For that matter, the Page class has a reference to the master page and therefore its control tree as well, so accessing any part of the page is quite possible.


if you don’t mind disgracian, can you help me by writing a code. please

Well, which approach are you looking at taking for this? Then we can help you with your code.

well, I like the settimeout method, because the System.Threading.Thread.Sleep(5000) will sleep the server. Actually, I don’t know how to insert a the settimeout in my code behind file. Because of the the example I found in web is through the use of the META tag. And if there’s something like settimeout example, it is not written in a code behind.

As I have suggested, by accessing the Page classes Master property, you can access the master page and programatically add meta tags, or you can just render a Javascript code block to the page using DOM methods to reload a different page.

And no, I’m not going to do your work for you. You’ve been pointed in the right direction, you should be able to do the rest yourself. Check the MSDN Library or w3schools Javascript reference if you get stuck.


okey…thanks disgracian