1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.