I'm running string.Format
on a readonly string that contains a bit of HTML + javascript but I get a System.FormatException
instead.
This is my format string:
<script type="text/javascript">
function {0}_showHideFieldWindow() {
if ({0}.IsCustomizationWindowVisible()) {
{0}.HideCustomizationWindow();
} else {
{0}.ShowCustomizationWindow();
}
}
</script>
All i'm doing is passing in the object name. Like this:
string.Format(javascript, "grid");
Since you have curly braces in the string you need to escape them by doubling them up ({{
and }}
) to prevent the formatter from thinking they are tokens.
Your string initialization should look something like this:
String javascript = @"<script type=""text/javascript"">
function {0}_showHideFieldWindow() {{
if ({0}.IsCustomizationWindowVisible()) {{
{0}.HideCustomizationWindow();
}} else {{
{0}.ShowCustomizationWindow();
}}
}}
</script>";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With