您的位置:首页 > 其它

Page.ClientScript.RegisterClientScriptBlock和Page.ClientScript.RegisterStartupScript区别

2015-05-25 11:05 351 查看

Page.ClientScript.RegisterClientScriptBlock可以在服务器端把javascript function放在页面的顶部。

protected void Page_Load(object sender, EventArgs e)

{

string myScript = @"function AlertHello() { alert('Hello ASP.NET'); }";

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),

"MyScript", myScript, true);

}

Page.ClientScript.RegisterStartupScript

The
RegisterStartupScript
method is not that different from the
RegisterClientScriptBlock

method. The big difference is that the
RegisterStartupScript
places the script at the bottom of the

ASP.NET page instead of at the top. In fact, the
RegisterStartupScript
method even takes the same

constructors as the
RegisterClientScriptBlock
method:



RegisterStartupScript
(type,
key,
script)



RegisterStartupScript
(type,

key,

script,

script tag specif cation)

protected void Page_Load(object sender, EventArgs e)

{

string myScript = @"alert(document.forms[0]['TextBox1'].value);";

Page.ClientScript.RegisterStartupScript(this.GetType(),

"MyScript", myScript, true);

}

Page.ClientScript.RegisterStartupScript
是把javascript方法放在页面的底部。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐