Skip to content Skip to sidebar Skip to footer

Passing Parameter From Aspx To Javascript Issue

I write code in asp.net backend to pass parameter, however, I found that it does not work if the parameter is so long. In the backend: folderList.InnerHtml += '\""+ folder.Id+"\")'>"+ folder.DisplayName+"</span>";

Using string concatenation to generate HTML is always error prone. Remember, the JavaScript string needs to be quoted as does the HTML attribute it is contained in. Since you are using single quotes for your attribute, you must use either double quotes or htmlencoded single quotes for your JavaScript. This should work:

"... onclick='AttachId(\""+ folder.Id+"\")'>"+...

Solution 2:

Actually, I believe the problem isn't with the length of your paramater, but instead with the included quote marks ".

Try escaping them.

Solution 3:

<spanonclick='AttachId(" + folder.Id + ")'>

I think this should be changed to -

<span onclick='AttachId('" + folder.Id + "')'>

So the variable is passed to the function as a string.

Post a Comment for "Passing Parameter From Aspx To Javascript Issue"