簡體   English   中英

如何使用ScriptManager的多個功能?

[英]How can I use ScriptManager more than one function?

if (mod != 1)
{
    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "Funcm()", true);
}

if (ven != 1)
{
    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "Funcv()", true);
}

if (loc != 1)
{
    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "Funcl()", true);

}

if (st != 1)
{
    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "Funcst()", true);
}

只有第一個“如果”有效且隱藏了該項目,而其他的則無效,如何解決此問題?

function Funcm() { document.getElementById("ModelMenu").style.display = "none";}
function Funcv() { document.getElementById("VendorMenu").style.display = "none";}
function Funcl() { document.getElementById("LocMenu").style.display = "none";}
function Funcst() { document.getElementById("StatusMenu").style.display = "none";}

然后嘗試更多類似的方法,即僅注冊一個腳本...

string myScript = string.Empty;

if (mod != 1)
{
    myScript += "document.getElementById(\"ModelMenu\").style.display = \"none\";";
}

if (ven != 1)
{
    myScript += "document.getElementById(\"VendorMenu\").style.display = \"none\";";
}

if (loc != 1)
{
    myScript += "document.getElementById(\"LocMenu\").style.display = \"none\";";
}

if (st != 1)
{
    myScript += "document.getElementById(\"StatusMenu\").style.display = \"none\";";
}

if (!string.IsNullOrEmpty(myScript))
{
    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "myScript", myScript, true);
}

或者如果您的功能是預定義的,則必須使用它們:

string myScript = string.Empty;

if (mod != 1)
{
    myScript += "Funcm();";
}

if (ven != 1)
{
    myScript += "Funcv();";
}

if (loc != 1)
{
    myScript += "Funcl();";
}

if (st != 1)
{
    myScript += "Funcst();";
}

if (!string.IsNullOrEmpty(myScript))
{
    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "myScript", myScript, true);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM