0

これを試してみると、私が呼んでいる行のタイトルに記載されているエラーが発生します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);
    }
} 
4

2 に答える 2

5

使用する場合は、文字通り出力したい文字と文字String.Formatをエスケープする必要があります。これらはJavascriptコードであるためです。これを実現するには、とをそれぞれ使用します。{}{{}}

文字列の書式設定について詳しくは、中括弧のエスケープに起因する奇妙な動作についても説明されています

于 2012-06-04T09:00:44.813 に答える
0

{次のようなafter関数宣言をエスケープする必要があると思います

String script = String.Format("$(document).ready(function()
{{ $('#{0}').dialog('open'); }});", divId);
于 2012-06-04T09:02:10.460 に答える