0

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.

Village
  • 199
  • 3
  • 15

1 Answers1

0

take a look at this thread ScriptManager.RegisterStartupScript code not working - why? it looks like you need to use GetType instead of typeof

protected void Page_PreRender(object sender, EventArgs e)
{
   ScriptManager.RegisterStartupScript(this, GetType(), "YourUniqueScriptKey", 
    "alert('This pops up');", true);
}
Community
  • 1
  • 1
DanielS
  • 744
  • 6
  • 13
  • This isn't the problem. If I give RegisterStartupScript a smaller string, say if I just pass "bla" to it instead, it calls the function and the string is passed just fine. I'm pretty sure the problem is either the formatting of the string or its size. I've already tried using replace to format it so most likely it's the size of the string. – Village Feb 21 '15 at 00:40
  • Have you tried looking in the network tab in dev tools? You can examine your request, to see if the whole string is passed to the server – DanielS Feb 21 '15 at 00:47