Stop further execution in Page_Load

Discussion in 'ASP .Net' started by Gopal Krish, Oct 24, 2004.

  1. Gopal Krish

    Gopal Krish Guest

    Folks,

    My ASPX page uses a custom user control. What happens here is that
    when a runtime error occurs in the ASPX page, the error is caught in
    the error handler and then strangely, the execution continues to the
    custom user control code and it blows there because of the error
    occured initially in the ASPX page. When it blows it displays as
    unhandled error even though I have try catch in my ASPX page and in
    the custom user control.

    Is there a way to stop execution if an error occurs in the Page_Load
    method and return the contents gathered so far back to the client
    (along with the error)?

    I tried Response.End and it returns an emppty screen to the client. I
    wanted to display whatever has been processed until the point where
    the error occured. Pls note this works fine for normal ASPX page but
    when I use a custom user control in my ASPX page then the execution
    continues to the custom user control code even after an error occured
    and caught in my ASPX page's try catch block.

    Any thoughts pls?
    Gopal Krish, Oct 24, 2004
    #1
    1. Advertising

  2. Gopal Krish

    Derek Harmon Guest

    "Gopal Krish" <> wrote in message news:...
    > Is there a way to stop execution if an error occurs in the Page_Load
    > method and return the contents gathered so far back to the client
    > (along with the error)?
    >
    > I tried Response.End and it returns an emppty screen to the client. I
    > wanted to display whatever has been processed until the point where
    > the error occured.


    I would answer Response.End as well. The reason you're seeing an empty
    screen is because during Page_Load -- that is all the content you have. No
    HTML is produced until Render (remember the page lifecycle: Init, Load,
    PreRender, Render, and Unload).

    If you want your catch statement to remove the offending WebControl(s)
    from the Page, so other controls can go on to render, that's one approach
    you could use (but you'll also require a way to dynamically put it back in
    Page_Init when the situation is repaired, if that's what you're going for).

    My suspicion is that you're not catching the exception from the user control,
    probably because you have try..catch in the Load events, but not during the
    processing wherein ASP.NET calls Render( ) on the Page and your User-
    Control. If your Page_Load begins with try and ends with catch, you're
    still missing out on the majority of the processing.


    Derek Harmon
    Derek Harmon, Oct 24, 2004
    #2
    1. Advertising

  3. Gopal Krish

    Gopal Krish Guest

    Thanks Derek. Now I understand the process fully. I think I should be
    able to handle it now.

    Thanks


    "Derek Harmon" <> wrote in message news:<>...
    > "Gopal Krish" <> wrote in message news:...
    > > Is there a way to stop execution if an error occurs in the Page_Load
    > > method and return the contents gathered so far back to the client
    > > (along with the error)?
    > >
    > > I tried Response.End and it returns an emppty screen to the client. I
    > > wanted to display whatever has been processed until the point where
    > > the error occured.

    >
    > I would answer Response.End as well. The reason you're seeing an empty
    > screen is because during Page_Load -- that is all the content you have. No
    > HTML is produced until Render (remember the page lifecycle: Init, Load,
    > PreRender, Render, and Unload).
    >
    > If you want your catch statement to remove the offending WebControl(s)
    > from the Page, so other controls can go on to render, that's one approach
    > you could use (but you'll also require a way to dynamically put it back in
    > Page_Init when the situation is repaired, if that's what you're going for).
    >
    > My suspicion is that you're not catching the exception from the user control,
    > probably because you have try..catch in the Load events, but not during the
    > processing wherein ASP.NET calls Render( ) on the Page and your User-
    > Control. If your Page_Load begins with try and ends with catch, you're
    > still missing out on the majority of the processing.
    >
    >
    > Derek Harmon
    Gopal Krish, Oct 25, 2004
    #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. Vinod I
    Replies:
    3
    Views:
    420
    Kelly Leahy
    Jan 16, 2004
  2. bminder
    Replies:
    1
    Views:
    2,147
    nfedin
    Feb 23, 2004
  3. Jason
    Replies:
    2
    Views:
    2,479
    =?Utf-8?B?U3RldmUgSw==?=
    Jun 10, 2004
  4. z. f.
    Replies:
    0
    Views:
    540
    z. f.
    Oct 19, 2004
  5. rockdale
    Replies:
    1
    Views:
    640
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Nov 16, 2006
Loading...

Share This Page