Trapping exceptions encountered in user controls

Discussion in 'ASP .Net' started by Yash, Jan 17, 2008.

  1. Yash

    Yash Guest

    Hi,

    I have create a user control which has a dropdown. The user control
    internaly handles the Selected_Index_Changed event of the dropdown. If
    there is an error/exception in handling it, I would like the
    containing page to know of it. How can I make this possible? The
    containing page does not know of the dropdown.

    Thanks,
    Yash
    Yash, Jan 17, 2008
    #1
    1. Advertising

  2. Yash

    JIGNESH Guest

    To give you an idea therotically.
    1. Declare event in your usercontrol.
    2. From your page trap the event UserControl += new MyEvent( ...... )
    3. OnException inside UserControl Raise the Event
    4. You Page event handdler will receive the event and execute your function.

    if you find difficult then i shall spend sometime to code and post it here.

    Regards
    JIGNESH

    "Yash" wrote:

    > Hi,
    >
    > I have create a user control which has a dropdown. The user control
    > internaly handles the Selected_Index_Changed event of the dropdown. If
    > there is an error/exception in handling it, I would like the
    > containing page to know of it. How can I make this possible? The
    > containing page does not know of the dropdown.
    >
    > Thanks,
    > Yash
    >
    JIGNESH, Jan 17, 2008
    #2
    1. Advertising

  3. Yash

    Patrice Guest

    It doesn't matter. The exception bubbles and will be handled at the parent
    level inside the hosting application (make sure you don't hide the exception
    in your user control ???)...
    --
    Patrice


    "Yash" <> a écrit dans le message de news:
    ...
    > Hi,
    >
    > I have create a user control which has a dropdown. The user control
    > internaly handles the Selected_Index_Changed event of the dropdown. If
    > there is an error/exception in handling it, I would like the
    > containing page to know of it. How can I make this possible? The
    > containing page does not know of the dropdown.
    >
    > Thanks,
    > Yash
    Patrice, Jan 17, 2008
    #3
  4. Yash

    Yash Guest

    But where will the try and catch be in the containg page to handle the
    bubbled exception?

    Raising an OnError event may work. But is there another way?
    Yash, Jan 17, 2008
    #4
  5. Yash

    Patrice Guest

    Either in the Page_Error event or in the global exception event handler (my
    personal preference)...

    The general idea is that exceptions are propagated automatically to callers.
    So the first step could be to check your first assumption. This is not
    because the dropdown is not an object known from the parent page that
    exceptions thrown there are not propagated back to the caller (it just uses
    the call stack to pass the exception to calling code).

    With this in mind the general principle would be to have a global error
    handler at the highest possible level so that you knows that something goes
    wrong and that you can fix the coding error. Then you can place a local
    exception handler at choosen places :
    - either because your code or the user could do something to solve the
    particular exception you are trapping at this place (and in this case you
    don't let this particular one to propagate higher)
    - or to do some cleanup on unmanaged resources (but in this case you still
    let the exception goes higher as once resources are released you still want
    to know that your application has en error you should fix).

    You should find more details areound :
    http://msdn2.microsoft.com/en-us/library/6kzk0czb.aspx

    --
    Patrice



    "Yash" <> a écrit dans le message de news:
    ...
    > But where will the try and catch be in the containg page to handle the
    > bubbled exception?
    >
    > Raising an OnError event may work. But is there another way?
    Patrice, Jan 17, 2008
    #5
  6. Yash

    Yash Guest

    Thanks
    Yash, Jan 18, 2008
    #6
    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. Durairaj Avasi
    Replies:
    1
    Views:
    1,006
    Slackware
    Apr 7, 2004
  2. Naveen Kumar soni

    ThreadAbortException Encountered

    Naveen Kumar soni, Jul 9, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    401
    Marina
    Jul 9, 2003
  3. =?Utf-8?B?SmVyZW15IEJyb3du?=

    Trapping Exceptions on an ObjectDataSource

    =?Utf-8?B?SmVyZW15IEJyb3du?=, Mar 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    764
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Mar 9, 2006
  4. rote
    Replies:
    13
    Views:
    466
  5. Griff
    Replies:
    2
    Views:
    107
    Uri Guttman
    Aug 27, 2004
Loading...

Share This Page