简体   繁体   中英

javascript output with double quote in asp.net c#

when i generate text from database using datatables in asp.net c#, i can generate this "<a href='javascript:txtreplace('text to replace')'>" + lbltext.Text + "</a>"

output is

<a onclick='txtreplace('text to replace')'>text</a>

but is in not working on webpage, it is noly working when onclick is in Ddouble quote like <a onclick="txtreplace('text to replace')">text</a>

how to generate text with double quote in "onclick" from database or any other solution to access javascript function

you need to prefix your strings with @ which makes it a verbatim string, then just use " two times

@"<a href=""javascript:txtreplace('text to replace')"">" + lbltext.Text  + @"</a>"

or you escape the " with a \

"<a href=\"javascript:txtreplace('text to replace')\">" + lbltext.Text  + "</a>"

here`s some more info about verbatim and regular strings in c#

http://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM