Hi all i have the following code
<%= Replace(FindAndReplace(objDR.Item("LENTAB_NAME") ),"'","\'") %>
in this we are replacing the ' character with \', which is working fine. but when i tried to enter values like '"" then it is giving scripting error as
')' expected
i tried to replace this thing as Replace(string,"'"","\'"")
but failed
can you please give me the solution to this!
Actually this is the code snippet
FoldersArray[FoldersArray.length] = new FoldersListItmes("<%= objDR.Item("TAB_ID") %>","<%= Replace(FindAndReplace(objDR.Item("LENTAB_NAME") ),"'","\\'") %>","<%= Replace(FindAndReplace(objDR.Item("TAB_NAME") ),"'","\'") %>" ,"<%=intCnt %>" )
i am using server side tags inside javascript function..开发者_运维问答.
Thanks
I'd imagine that you have to escape your escape character as well, since \
has a special meaning when used inside strings.
So essentially use "\\'"
.
You could just escape the quotes (you need to escape your backslash, as @Steve Wang mentioned), but then other characters (line newlines) will mess you up.
If you're using a recent version of ASP.Net, you may want to use the HttpUtility.JavaScriptStringEncode
to encode all of the necessary characters. Sadly, that appears to be quite new, in .Net 4.
(That MSDN page mentions URL encoding, but I'm fairly sure that's just because Microsoft assigns their most entry-level staff to MSDN documentation; the function has nothing to do with URL encoding.)
精彩评论