如何使用 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);
}
只有第一个 "if" 有效并隐藏了该项目,但其他的无效,我该如何解决这个问题?
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);
}
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);
}
只有第一个 "if" 有效并隐藏了该项目,但其他的无效,我该如何解决这个问题?
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);
}