ScriptManager + JavaScript alert missing ... Where did it go?

Last post 07-01-2008 7:00 PM by burlmd. 5 replies.

Sort Posts:

  • ScriptManager + JavaScript alert missing ... Where did it go?

    11-29-2007, 10:25 AM
    • Loading...
    • c0ugar2
    • Joined on 11-29-2007, 3:00 PM
    • Posts 3

    Hello,

    My colleague was using the ScriptManager's AsyncPostBackError event to change an exception message and once this event finished, a JavaScript alert message box was displayed alerting the user. Now, with either the new AJAX 3.5, or .NET 3.5, or Visual Studio 2008, or any combination of the 3, the JavaScript alert does not show up. Instead, Internet Explorer indicates to the user a JavaScript error has occurred and no message box is shown. 

    I have read many posts by members stating that the JavaScript alert box shows up and they would like to disable it but I on the other hand would like the message to pop-up. I tried using ScriptManager.RegisterStartupScript to throw an alert box up at the end of the event but that does not seem to do anything at all.

    If I use the following in the body of my HTML.. 

    <script type="text/javascript">

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);

    function EndRequest(sender, args)

    {

    if (args.get_error())

    {

    alert(args.get_error().description);

    args.set_errorHandled(
    true);

    }

    }

    </script>

    This works except my custom error message is displayed along with the Exception type to the left which I cannot remove.

     Example: Sys.WebForms.PageRequestManagerServerErrorException: Please select whether this address is residential or commercial.

    I'd like the alert to just say, 'Please select whether this address is residential or commercial'

    Does anyone have any idea how I can make this work?

    Suggestions and comments are greatly appreciated.

     -- Rick

  • Re: ScriptManager + JavaScript alert missing ... Where did it go?

    12-06-2007, 10:05 AM
    Answer

    Hi Rick,

    Please do it like this.

    <script type="text/javascript" language="javascript">
       Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(sender, e)
       {
        e.set_errorHandled(true);
        $get("error").innerHTML = "Sorry, an error has occurred: " + e.get_error().message;
        setTimeout(function(){ $get("error").innerHTML = ""; }, 3000);
       });
      </script>

    Also , you can see this document.

    I hope this help.

    Best regards,

    Jonathan

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: ScriptManager + JavaScript alert missing ... Where did it go?

    12-06-2007, 10:53 AM
    • Loading...
    • c0ugar2
    • Joined on 11-29-2007, 3:00 PM
    • Posts 3

    Thanks for your help Jonathan. This method will work just not sure why our previous method stopped working. Must have been because of either .NET 3.5 or AJAX 3.5, or both.

  • Re: ScriptManager + JavaScript alert missing ... Where did it go?

    12-07-2007, 12:36 AM

    Hi Cougar2,

    I would like to suggest that you should add debugger to your code and use Visual Studio 2008 to see all the methods and properties.

    Best regards,

    Jonathan 

     

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: ScriptManager + JavaScript alert missing ... Where did it go?

    01-20-2008, 11:53 PM
    • Loading...
    • selap
    • Joined on 05-09-2006, 3:51 PM
    • Posts 1

    You may have figured it out already but I also noticed a change in 3.5 where the AsyncPostBackError wasn't getting handled where it had been just fine in 2.0. Turns out that we had custom Application_Error handling in our global.asax which would redirect to an appropriate error page. While this wasn't getting called in 2.0 it does get called in 3.5. So.. if that's your issue then you'll need to either check for the error type and only redirect on certain types and/or check to see if the current context handler is in an async postback within the Application_Error. If the current page handler is in async postback then don't redirect.

     Hope that helps somebody who is running in to similar problems.
     

  • Re: ScriptManager + JavaScript alert missing ... Where did it go?

    07-01-2008, 7:00 PM
    • Loading...
    • burlmd
    • Joined on 01-04-2008, 11:29 AM
    • Posts 11
    I am having the same issues as Rick where the custom error message is getting prepended with

    "Sys.WebForms.PageRequestManagerServerErrorException: " 

    And so my error message reads:

    "Sys.WebForms.PageRequestManagerServerErrorException: This security already exists in this account.

    Stack Trace:
    PG.ProposalSystem.IndividualHolding.AddSecurityButton_Click() line 97
     PrimaLibrary"

    I've looked at the code and this is happening in the Sys$WebForms$PageRequestManager$_createPageRequestManagerServerError() function on the client.  Is there anyway to get the original error message? 

     

    I've tried your suggestion, but e.get_error().message = "Sys.WebForms.PageRequestManagerServerErrorException: This security already exists in this account.

    Stack Trace:
    PG.ProposalSystem.IndividualHolding.AddSecurityButton_Click() line 97
     PrimaLibrary"

     and e.get_error().description gives the same results too.

     

    Any ideas?

     

    Thanks.

Page 1 of 1 (6 items)
Microsoft Communities
Page view counter