The dynamically created JavaScript function does not work with a long parameter

advertisements

I have several html A tag generated programmatically in ASP.NET with a JavaScript function taking long parameter in href. One of those has over 20K characters when it get assigned in backend, but I am seeing the actual link has only 5239 characters on the browser side and the JavaScript function does not have closing. So the link never works. I am thinking about workarounds for this implementation since it's not a good idea to put this much amount of data in links, but now I'm just curious about cause of the issue.

Examples of the code assigning values to the link:

HtmlAnchor.HRef = "javascript:doSomething('Import','" + strHeader_LineIds + "');"

In this case the variable strHeader_LineIds carries a string over 20k characters.

Example of what I'm actually seeing in client side:

<a id=anchor1 class=class1 href="javascript:doSomething('Import', 'blahblahblahblah....">Link Text</a>

Please note the javascript function has no closing here. But when I'm debugging in backend I do see the closing of the function.

I guess this issue may have something to do with the browser's URL limit? I am using IE and I learned IE has a maximum URL length limit as 2,083 characters from Here. But how can the link show up with 5,239 characters?


I've had a similar issue with javascript like dynamic functions created in code and then called. I found that I had to play with swapping out single quotes in the javascript function with double quotes or escaping the quotes.

Then again just reading your post could be a limit issue.

Have you tried assigning the long to an element in the background and then referencing that as part of the javacript. I know IE gets funny with spaces in passed in parameters.