 |
| 我的知识库 |
 |
|
|
ASP.NET中的doPostBack脚本函数实例 |
|
[ 作者: | 文章来源: 网页教学网 | 点击数: 471 | 更新时间: 2007-11-4 8:57:54 ] |
今天来说说当ASP.NET中的doPostBack脚本函数的应用,ASPX页面有包含asp:LinkButton或者带有AutoPostBack属性且其值为true的服务器控件时,ASP.NET会自动为页面生成下面的脚本: 中国南通服务器网
以下为引用的内容: function __doPostBack(eventTarget, eventArgument) { if(!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); 中国南通服务器网 } } |
南通服务器网
__doPostBack带有两个参数:eventTarget和eventArgument。 Spdns
eventTarget是引起回送的控件的ID,eventArgument是回调参数(与控件相关的附加数据)。这两个参数分别由隐藏的两个表单域__ EVENTTARGET和__ EVENTARGUMENT保存。 中国南通服务器网
使用这两个隐藏的表单可以查找引起页面回送的控件ID和回送时的参数: Www~Spdns~com
以下为引用的内容: protected void Page_Load(object sender, EventArgs e) { string target = Request.Params["__EVENTTARGET"]; string args = Request.Params["__EVENTARGUMENT"]; } |
中国.南通服务器网
因为asp:Button和asp:ImageButton不是使用__doPostBack回送页面,所以使用这两个控件回送页面时,上面的代码是无效的。 Www~Spdns~com
使用HTML控件回送页面: 中国南通服务器网
以下为引用的内容: protected void Page_Load(object sender, EventArgs e) { if(this.IsPostBack) { string target = Request.Params["__EVENTTARGET"]; 中国.南通服务器网 string args = Request.Params["__EVENTARGUMENT"]; Response.Write("Button ID: " + target + " "); Response.Write("Arguments: " + args + " "); } } |
中.国.南通服务器网
加入的目的是为了让ASPX自动生成__doPostBack脚本。 中国南通服务器网
阻止asp:Button提交页面: 中.国.南通服务器网
以下为引用的内容:
protected void Page_Load(object sender, EventArgs e) { string scr = "return confirm(’Are you sure you want to submit this form?’);"; this.Button1.Attributes.Add("onclick", scr); } 南通服务器网
|
Www_Spdns_com
|
|
|
|
|