I want to display messages from my asp.net pages by registering a script, sometimes even the exception code from an error. I use this code:
ScriptManager.RegisterStartupScript(this, Page.GetType(), "NoDept", "alert('Adjustments require the Total Amount to be ZERO to post!');", true);
This works great if I can decide the information to display during development, but if I want to display something that is data from the application, it may include invalid text, which of course screws up the script and it does not display. An example would be something with ' in the message.
I am running into the problem when I try to display a message from an exception such as:
ScriptManager.RegisterStartupScript(this, Page.GetType(), "processError", "alert('" + ptcred.TransactionError + "');", true);
The ptcred.TransactionError is the ASP.NET Exception error, and it may contain invalid characters.
What would be the best way to handle presenting this information in my alert() function that will not screw up my javascript? Possibly something that jQuery could do to clean it up?
EDIT: I should explain, I would like to continue to easily just register an alert script, its easy and convenient. Just wondered if there wsa something like HTML.Encode or something that will clean up infromation that will make a message not screw up the script.
Thanks, Cory
Error
orstring Message