Server.Transfer doesn't work in a timer callback

J

Jim Hammond

The code below works except that calling Server.Transfer generates the
following exception, and I don't know why yet:

"Error executing child request for Form_Welcome.aspx."

Although a page has a short lifespan, I have discovered that the timer
callback is in fact being called after 10 seconds.

Notet hat "p" appears to be perfectly valid and returns equal when compared
to the original Web Form object, which I saved using Application.Add
specifically to test for such equality.


private void Page_Load(object sender, System.EventArgs e)
{
// Set timer to call Page_PostLoad in 10 seconds
timerDelegate = new TimerCallback(Page_PostLoad);
timer = new Timer( timerDelegate, this, 10000, 0 );
}

static void Page_PostLoad(Object page)
{
Form_ProceedToDesk p = (Form_ProceedToDesk)page;
try
{
// stop timer
p.timer.Dispose();
p.timer = null;
p.GoHome();
}
catch(Exception ex)
{
p.ExceptionDisplay( ex );
}
}

public void GoHome( )
{
Server.Transfer("Form_Welcome.aspx");
}
 
C

Colin Young

It looks to me like you are trying to redirect the user to a new page after
10 seconds. You need to use client-side code to do that, not server-side
code. I think if you search for "meta refresh" you should find an example of
how to do it.

Colin
 
J

Jim Hammond

It looks to me like you are trying to redirect the user to a new page after
10 seconds. You need to use client-side code to do that, not server-side
code. I think if you search for "meta refresh" you should find an example of
how to do it.

Colin


Thanks,

That seems to work fine, but I now have three concerns because I thought it
was supposed to be possible to do everything in C#.
1. I manually edited the .aspx file, which means that my code is not as
clean and is harder to maintain.
2. Will server-side code know how to handle the redirection caused by the
META tag as well as if I had used C#?
3. Note that Visual Studio lets the developer drag and drop a timer onto the
web form, which now seems like a pointless feature.

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top