I am trying to create a simple JavaScript file to inject from code behind and want to append variables names to message.
string javascript = string.Format
(
@"var msg = '{0} ';
if(confirm(msg))
{
hdnfield.value='Yes';
} else {
hdnfield.value='No';
}
submit();", variableName);
but getting an FormatException. What is the right way to do this?
Thanks as always.
Your braces in the if/else statement are not escaped, that is causing problems with the call to
string.Formatwhich uses braces to indicate the placeholders.