I have below code behind in c#
if (Session["cmpDictionaryTitle"]!= null)
{
downloadLinks.Text += @"<li><a onclick='pageTracker._trackEvent('dictionary', 'spanish');' target ='_blank' href=" + Session["cmpDictionaryTitle"] + ">" + GetResourceString("c_DictionaryPDFName") + "</a></li>";
}
I am trying to make below <a> link as shown below:
<li><a target ="_blank" href="/spa/Images/Diccionario_tcm25-18044.pdf" onclick="pageTracker._trackEvent('dictionary', 'spanish');">Diccionario de Español-Inglés GRATIS</a></li>
However my c# code is generating below output when html page get renders, the reason is that I am not able to put proper quotes in my code behind.
<li><a );="" spanish="" ,="" dictionary="" onclick="pageTracker._trackEvent(" href="/spa/Images/Diccionario_tcm25-18044.pdf" target="_blank">Diccionario de Español-Inglés GRATIS</a></li>
Can you please suggest how can I achieve above result in code behind.
Thanks & Best Regards
To use a double-quote in a string built in code, either:
like this: “\””.
“””” (when using
@to create a verbatimstring literal).
Examples:
Here’s your original code using backslash-escaped double-quotes for all the attributes (I’ve chosen the first approach and removed the leading
@):Finally, I recommend reading Jon Skeet’s excellent article “Strings in .NET and C#.”