I'm trying to pass a string from my code behind to a JavaScript function in my .aspx file. This works fine if I pass a short dummy string, like "bla." But when I pass it a full exception message + stack trace the program hangs and does not enter the JavaScript function.
Here is how I'm trying to accomplish this:
ScriptManager.RegisterStartupScript(this, typeof(string), "loading log message popup", String.Format("LogMessagePopup('{0}')", logMessage), true);
On my server-side is the LogMessagePopup JavaScript function,
function LogMessagePopup() {
...
The contents of the JavaScript function don't matter.
The problem, possibly, is that the logMessage is very long. It is an entire exception and stack trace, over 4KB.
If I pass a shorter message, my code works fine.
There may also be issues with special characters, but after using logMessage.replace to escape special characters in JavaScript the problem persists.
I've been reading that you can pass longer strings via POST to the server-side code, but I don't understand how to do this, if this is even the solution I'm looking for, because I don't know how to pass it to my JavaScript LogMessagePopup function specifically. The string gets lost somewhere along the way.