以 ClientScriptManager.RegisterClientScriptBlock Method (Type, String, String) 为例看到N多代码 写的是 this.GetType()msdn 上写的是
Type: System.Type
The type of the client script to register. 这个type 有什么含义
如果我这样写 又有什么区别?ScriptManager.RegisterStartupScript(this.updatePanel1, this.GetType(), "hello1", "alert('Hello World!');",true);ScriptManager.RegisterStartupScript(this.updatePanel1, this.updatePanel1.GetType(), "hello1", "alert('Hello World!');",true);
Type: System.Type
The type of the client script to register. 这个type 有什么含义
如果我这样写 又有什么区别?ScriptManager.RegisterStartupScript(this.updatePanel1, this.GetType(), "hello1", "alert('Hello World!');",true);ScriptManager.RegisterStartupScript(this.updatePanel1, this.updatePanel1.GetType(), "hello1", "alert('Hello World!');",true);
我注册成 Page GetType() 与 Control GetType() 有什么不同么?
这没什么关系吧,IsStartupScriptRegistered 会判断 脚本的key 和 type 以此避免重复注册js但这和我理解 Type 参数本身的意义 有什么矛盾么???
msdn 上只是说 这个客户端脚本的类型, 但这个类型有什么意义?
如果没有特殊的意义 那微软没有必要加上这么一个参数 直接检查 key 就可以了。 不可不讲究。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
是否注册了key 为js的代码段 不指定Type <%= noType %>
<hr />
是否注册了key 为js的代码段 指定Type <%= hasType %>
</form>
</body>
</html>
protected bool noType, hasType; protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "js", "var js;", true);
ClientScript.RegisterStartupScript(new Literal().GetType(), "js", "var js1;", true); noType = ClientScript.IsStartupScriptRegistered("js"); hasType = ClientScript.IsStartupScriptRegistered(GetType(), "js");
}