The status code returned from the server was: 500 while tring to display MessageBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PPrasanna
    New Member
    • Dec 2009
    • 6

    The status code returned from the server was: 500 while tring to display MessageBox

    I am back in .net after a long break.. i am stuck with a problem ..

    I have coded to display a message box using "System.Windows .Forms.MessageB ox.Show " to show up based on condition and this works fine in my local machine but when i publish the site and put the .dll out for testing i am getting an error saying

    ---------------------------
    Microsoft Internet Explorer
    ---------------------------
    Sys.WebForms.Pa geRequestManage rServerErrorExc eption: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500
    ---------------------------
    OK
    ---------------------------
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    You really shouldn't be using windows.forms namespace in a web application.
    Besides, it would only popup a messagebox on the server, not on the client.

    That's what javascript's Alert() is for

    Comment

    • PPrasanna
      New Member
      • Dec 2009
      • 6

      #3
      Thanks for your reply. I have tried using Alert but got an Parser error message, can you please gv me any examples if you have.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Ok.

        Simple javescript:
        [code=javascript]
        <script type="text/javascript">
        alert('hi!');
        </script>
        [/code]


        In ASP.NET:
        [code=c#]
        string namestr="Plater ";
        MyClickableCont rol.Attributes. Add("onclick", "Alert('How dy there '"+namestr+");" );
        [/code]

        Comment

        • PPrasanna
          New Member
          • Dec 2009
          • 6

          #5
          Thanks for your reply.. I am still getting below error

          code snap:

          Response.Write( "<script type='text/javascript'> alert('Cant Save Data Again After Submit'); </script>");

          Error:
          ---------------------------
          Microsoft Internet Explorer
          ---------------------------
          Sys.WebForms.Pa geRequestManage rParserErrorExc eption: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write( ), response filters, HttpModules, or server trace is enabled.

          Details: Error parsing near '<script type='text/j'.
          ---------------------------
          OK
          ---------------------------

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            How to use JavaScript in ASP.NET

            Do not use Response.Write( )

            Why?
            It breaks parses ;)

            Basically it's going to output to "somewhere" in the response. This is typically in an invalid place.

            For example if you use Response.Write( "<script type='text/javascript'> alert('Cant Save Data Again After Submit'); </script>") it's likely that the HTML generated looks something like:

            Code:
            <script type='text/javascript'> alert('Cant Save Data Again After Submit'); </script>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            4<html xmlns="http://www.w3.org/1999/xhtml"> 
            
            ....
            Notice how the output is before the doctype and the HTML tag?
            Well this is invalid and IE8 has a perfectly good reason to be complaining.

            You can use Response.Write in your ASP code for the page.
            that way it is the Response.Write( ) is called in a Valid place in the HTML.
            For example in your ASPX code you could have something like:
            Code:
            <%@ Page Language="C#" .... %>
            
            <!-- your asp.net controls here -->
            
            <script type="text/javascript">
              alert('<%Response.Write("Cannot Save blah blah"); %>'); 
            </script>
            If you really want to generate your JavaScript server side then you should be registering it with your Page using the Page.ClientScri pt.RegisterStar tupScript method or if you're page is Ajax enabled, using the ScriptManager.R egisterClientSc riptBlock Method.

            -Frinny

            Comment

            • PPrasanna
              New Member
              • Dec 2009
              • 6

              #7
              now i have below code but still it does not work but i dont get any error also.. corrections please
              Code:
              string test = "<script language='javascript'>alert('Cant Save Data Again After Submit');</script>";
              ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('" + test + "');</script>");
              Last edited by Frinavale; Dec 21 '09, 02:28 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                You are mixing example codes. Take a look at what I put and take a loot at what Frinavale put. You are mixing them up

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  PPrasanna, what you posted doesn't make any sense.
                  You have a string "test" which contains:
                  Code:
                  <script language='javascript'>
                  alert('Cant Save Data Again After Submit');
                  <script>
                  Then, when you're registering the script with the page, you are adding an additional <script> tag and adding an alert with the test inside it...

                  So your resulting JavaScript is going to look like:
                  Code:
                  <script>
                  alert('<script language='javascript'>
                  alert('Cant Save Data Again After Submit');
                  <script>');
                  </script>
                  This doesn't make any sense...and it won't work because the string within the outter alert is being cut off by the apostrophe (') that is part of the inner script tag ...which is obviously causing JavaScript problems.

                  Try:
                  Code:
                  string test = "<script language='javascript'>alert('Cant Save Data Again After Submit');</script>";
                  ClientScript.RegisterStartupScript(this.GetType(), "alert", test);


                  -Frinny

                  Comment

                  • PPrasanna
                    New Member
                    • Dec 2009
                    • 6

                    #10
                    Hi Frinny,

                    Sorry that was my mistake to post wrong code i had the same code as you have told above but still its not working even though i dont get any error message. But also required message box do not pop out..

                    string test = "<script language='javas cript'>alert('C ant resubmit');</script>";
                    ClientScript.Re gisterStartupSc ript(this.GetTy pe(),"alert",te st);

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      Are you seeing any JavaScript errors in the page?
                      Are you using Ajax (UpdatePanels)?

                      What browser are you using to debug your JavaScript? IE8 comes with some built in debugging tools that really help...if you are using FireFox then you should download a tool like FireBug to help you find and debug any JavaScript errors on the page. I'm constantly switching between IE8's debugging tools and FireBug because each one will catch errors specific to each browser (and sometimes one finds errors that the other can't even when it's not a browser specific problem)

                      -Frinny

                      Comment

                      • PPrasanna
                        New Member
                        • Dec 2009
                        • 6

                        #12
                        Thanks for your quick response.. I am not getting any Javascript error and there is no ajax being used in my application the only thing i suspect is because of the browser as i have IE 6.0

                        Comment

                        • Frinavale
                          Recognized Expert Expert
                          • Oct 2006
                          • 9749

                          #13
                          Well, IE6 is pretty nasty but it should still know what to do with an alert().
                          As far as I know there are no JavaScript debugging tools available for IE6....So for now, to debug this, could you download and install FireFox...then download and install FireBug (which is a an add on for FireFox)?

                          Comment

                          • Plater
                            Recognized Expert Expert
                            • Apr 2007
                            • 7872

                            #14
                            I suspect the trouble is this:
                            ClientScript.Re gisterStartupSc ript(this.GetTy pe(), "alert",tes t);
                            You named it alert, try naming it "myAlert"

                            I also do NOT recomend firebug, it used to be usefull and a huge memory leak. Now I think they fixed the memory leak but it almost worthles.
                            The javascript error console (ctrl+shift+j) contains pretty much everything you need.
                            Last edited by Plater; Dec 21 '09, 07:19 PM. Reason: added SHIFT

                            Comment

                            • Frinavale
                              Recognized Expert Expert
                              • Oct 2006
                              • 9749

                              #15
                              FireBug is constantly changing. There was a time when it had some memory leaks and other problems (which really annoyed me because the previous version to was fine) but most problems have been fixed....it does sometimes totally miss errors...but it's not completely useless!

                              I've never used ctrl+j...is this for IE? Does it work in IE6? Does it provide more details than "object expected" error descriptions?

                              -Frinny

                              Comment

                              Working...