如何使用ScriptManager多个函数?

时间:2015-08-17 11:18:31

标签: c# asp.net asp.net-ajax scriptmanager

MyController

只有第一个" if"工作和隐藏项目,但其他人不工作,我该如何解决这个问题?

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);
}

1 个答案:

答案 0 :(得分:0)

然后尝试更喜欢这样的东西,即只注册一个脚本......

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);
}