args.get_error()

Last post 10-14-2008 6:04 PM by Antho71. 3 replies.

Sort Posts:

  • args.get_error()

    03-14-2008, 4:29 AM
    • Member
      3 point Member
    • jikilan
    • Member since 03-03-2008, 10:08 AM
    • Posts 6

    Hi,

    Anyone know what is the list of message properties for args.get_error(), so far what i know is args.get_error().description, args.get_error().message.

    When my updatepanel receive error, it always show me the below string.
    "Sys.WebForms.PageRequestManager.ServerErrorException: xxxx error "

    How to get only the error message message "xxxx error"? because  I dont want to display   "Sys.WebForms.PageRequestManager.ServerErrorException:"

    args.get_error().message will return the above string

    args.get_error().description  will return same string in IE but error in firefox

    Please advise. Thank you. 

    Regards,
    KSK

     

    Filed under:
  • Re: args.get_error()

    03-14-2008, 1:24 PM
    Answer

    A workaround would be to use a wrapper function, then parse out the desired info.

     

    function getError(args) {
        var err = args.get_error();
        var txt = err.split(":")[1];

        return txt;

     

    The syntax for Split() is probably off, but you should get the idea. 

  • Re: args.get_error()

    03-18-2008, 9:27 PM
    • Member
      3 point Member
    • jikilan
    • Member since 03-03-2008, 10:08 AM
    • Posts 6

    Is this a correct way to do it? is the any other formal way?

  • Re: args.get_error()

    10-14-2008, 6:04 PM
    • Member
      124 point Member
    • Antho71
    • Member since 01-20-2005, 12:00 PM
    • County Mayo, Republic of Ireland
    • Posts 29

    Hi all,

    Here's my two cents!

    In an attempt at answering your first question, "what are the list of properties for 'args.get_error()'?"

    args.get_error().name
    args.get_error().message
    args.get_error().description
    args.get_error().httpStatusCode
     (For info on the 'Error Object' see: http://msdn.microsoft.com/en-us/library/21x3h1hz.aspx)

     
    "The description and message properties refer to the same message; the description property provides backwards compatibility, while the message property complies with the ECMA standard" - source: http://msdn.microsoft.com/en-us/library/t9zk6eay.aspx

    You can also add some client-side JavaScript to the event handler bound to the 'endRequest' event of the 'PageRequestManager', to return the members of 'args.get_error()'. The split() method (mentioned above) is used to 'split' a string into an 'array of strings' and since an object is being returned from the ScriptManager's AsyncPostBackError... that is not going to help us here. Fortunately, JavaScript offers a special construct, “for in”, that allows you to easily iterate over all the members of an object without having to write customised code to accomplish the task:

    var errObj = args.get_error();
    var members = 'The \'get_error\' members are:\n\n';
    for (var i in errObj){
       members += '\t' + i + '\n';
    }
    alert(members);

     

    In an attempt at answering your latter question... you can alter the message displayed to the user either client-side or server-side. I personally found the following two pages very useful. They are well worth a read:

    How to improve ASP.NET AJAX error handling

    Customizing Error Handling for ASP.NET UpdatePanel Controls

     

    Please note: If you wish to prevent the JavaScript alert alert box for being displayed, you need to let the framework know that the error has been handled. As you'll see mentioned in the pages listed above, this is taken care of with:

    args.set_errorHandled(true);

     

    I read somewhere that version 3.5 of the framework does not fire the alert box? I've not tested this though, but just something to maybe lookout for.


    I hope this helps someone!


    Warm regards,

    Anthony Walsh

    #Please# remember to click "Mark as Answer" on the post that helps you. This can be beneficial to other community members reading the thread.
Page 1 of 1 (4 items)