I try this and it gives the error mentioned in the title at the line I call String.Format.
public static void JqueryDialogue(string divId)
{
String script = String.Format(
"$(document).ready(function(){ $('#{0}').dialog('open'); });",
divId);
// Gets the executing web page
Page page = HttpContext.Current.CurrentHandler as Page;
string codeId = "openDialoge" + divId.ToString();
// Checks if the handler is a Page and that the script isn't already on Page
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered(codeId))
{
page.ClientScript.RegisterStartupScript(
typeof(JavascriptHelper),
codeId,
script,
true);
}
}
If you use
String.Formatyou’ll need to escape the{and}characters that you want to be outputted literally since they are Javascript code. To achieve this you use{{and}}respectively.You can read more about string formatting here where an odd behavior resulting from escaping curly braces is also explained.