Server.Transfer doesn't work in a timer callback

Discussion in 'ASP .Net' started by Jim Hammond, Oct 21, 2003.

  1. Jim Hammond

    Jim Hammond Guest

    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");
    }
     
    Jim Hammond, Oct 21, 2003
    #1
    1. Advertising

  2. Jim Hammond

    Colin Young Guest

    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

    "Jim Hammond" <> wrote in message
    news:%23rajvx%...
    > 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");
    > }
    >
    >
    >
     
    Colin Young, Oct 21, 2003
    #2
    1. Advertising

  3. Jim Hammond

    Jim Hammond Guest

    "Colin Young" <> wrote in message
    news:%23$...
    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
     
    Jim Hammond, Oct 24, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Hammond

    Doesn't Timer class work in a Web Form?

    Jim Hammond, Oct 20, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    572
    mikeb
    Oct 21, 2003
  2. Karl
    Replies:
    2
    Views:
    2,414
    clintonG
    Aug 12, 2004
  3. Replies:
    1
    Views:
    1,679
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  4. FET
    Replies:
    3
    Views:
    527
    Chris Smith
    Sep 24, 2004
  5. Jim
    Replies:
    1
    Views:
    986
    Aaron Bertrand - MVP
    Jan 28, 2004
Loading...

Share This Page