Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. java sript in code behind C#

java sript in code behind C#

Scheduled Pinned Locked Moved ASP.NET
helpcsharpjavajavascripttools
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    omlac
    wrote on last edited by
    #1

    Im tying to write an exception message using javascript in code behind, using catch (Exception ex) { string err = ex.Message; string script = "alert('" + err + "');"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Msg", script, true); } But sometimes the message doesnt get dislayed and the whole application freezes, i have noticed that its caused by the content of ex.Message eg "Unable to cast object of type 'System.DBNull' to type 'System.String'." - gives a problem. The easiest thing to do is to replace the ' signs and it works fine, but this is applies to this error message only, is there a generic solution for this problem. Thank you.

    A L 2 Replies Last reply
    0
    • O omlac

      Im tying to write an exception message using javascript in code behind, using catch (Exception ex) { string err = ex.Message; string script = "alert('" + err + "');"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Msg", script, true); } But sometimes the message doesnt get dislayed and the whole application freezes, i have noticed that its caused by the content of ex.Message eg "Unable to cast object of type 'System.DBNull' to type 'System.String'." - gives a problem. The easiest thing to do is to replace the ' signs and it works fine, but this is applies to this error message only, is there a generic solution for this problem. Thank you.

      A Offline
      A Offline
      am net
      wrote on last edited by
      #2

      try with.. this catch (Exception ex) { response.write("'alert(' + ex.Message + ');'"); }

      O 1 Reply Last reply
      0
      • A am net

        try with.. this catch (Exception ex) { response.write("'alert(' + ex.Message + ');'"); }

        O Offline
        O Offline
        omlac
        wrote on last edited by
        #3

        Thank you for your response, but there is no output from response; i just took it as you wrote it, maybe its the synhax for response i will chaeck that and will come back to u. Thank u.

        S 1 Reply Last reply
        0
        • O omlac

          Im tying to write an exception message using javascript in code behind, using catch (Exception ex) { string err = ex.Message; string script = "alert('" + err + "');"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Msg", script, true); } But sometimes the message doesnt get dislayed and the whole application freezes, i have noticed that its caused by the content of ex.Message eg "Unable to cast object of type 'System.DBNull' to type 'System.String'." - gives a problem. The easiest thing to do is to replace the ' signs and it works fine, but this is applies to this error message only, is there a generic solution for this problem. Thank you.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You can try Response.write("alert('" + err + "');"); You can also try placing a label on the page then assign text to label as message.Text = "");

          1 Reply Last reply
          0
          • O omlac

            Thank you for your response, but there is no output from response; i just took it as you wrote it, maybe its the synhax for response i will chaeck that and will come back to u. Thank u.

            S Offline
            S Offline
            Sundar_R
            wrote on last edited by
            #5

            response.write("<script>'alert(' + ex.Message + ');'</script>"); this wont work if you have ' in the exception message think we have to write a method which replaces all special characters (ex: ' with \' and " with \")

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups