C# .NET - Escaping the Single Quote given in a javascript called dynamically

Asked By Vishwa I on 01-Oct-13 08:07 AM
I am calling a javascript function onclick of an anchor tag created dynamically as shown in the below code
datarow[drScheme["DESCRIPTION"].ToString() + "<br/>" + drScheme["PRODUCTCODE"].ToString()] = @"<a href='#' onclick='javascript:openPOPUP(\u0027'" + DiscountRate + "','" + CurrencyType + "','" + ProductCode + "','" + RegCode + "','" + drSchemeRule["SchemeId"] + "');'>" + DiscountRate + " " + CurrencyType + "</a>";

After rendering the onclick appears like as follows
onclick="javascript:openPOPUP(" 'DiscountRate ','CurrencyType ','ProductCode ','RegCode ','SchemeId');'

What wrong I am doing here? Please give me the solutions for this.
Robbe Morris replied to Vishwa I on 01-Oct-13 08:57 AM
Escape the double quotes single side instead of the single quotes.


var mystring = @"<a href=\"javascript:void\" onclick=\"openPopUp('" + someVariable + "');\" >Some link</a>
Vishwa I replied to Vishwa I on 09-Oct-13 06:06 AM
Thanks Morris, that helped me to fix the problem.