- TEL:131 7970 3111
-
慧網(wǎng)微信
- 掃描二維碼
- 關(guān)注邳州在線
-
手機(jī)網(wǎng)站
- 手機(jī)掃描二維碼
- 進(jìn)入手機(jī)站
網(wǎng)站地圖
付款方式
來(lái)說(shuō)說(shuō)當(dāng)ASP.NET中的doPostBack腳本函數(shù)的應(yīng)用,ASPX頁(yè)面有包含asp:LinkButton或者帶有AutoPostBack屬性且其值為true的服務(wù)器控件時(shí),ASP.NET會(huì)自動(dòng)為頁(yè)面生成下面的腳本:
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
function __doPostBack(eventTarget, eventArgument) {
if(!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
__doPostBack帶有兩個(gè)參數(shù):eventTarget和eventArgument。
eventTarget是引起回送的控件的ID,eventArgument是回調(diào)參數(shù)(與控件相關(guān)的附加數(shù)據(jù))。這兩個(gè)參數(shù)分別由隱藏的兩個(gè)表單域__ EVENTTARGET和__ EVENTARGUMENT保存。
使用這兩個(gè)隱藏的表單可以查找引起頁(yè)面回送的控件ID和回送時(shí)的參數(shù):
protected void Page_Load(object sender, EventArgs e)
{
string target = Request.Params["__EVENTTARGET"];
string args = Request.Params["__EVENTARGUMENT"];
}
因?yàn)閍sp:Button和asp:ImageButton不是使用__doPostBack回送頁(yè)面,所以使用這兩個(gè)控件回送頁(yè)面時(shí),上面的代碼是無(wú)效的。
使用HTML控件回送頁(yè)面:
<form id="form1" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server"></asp:LinkButton>
<input type="button" value="Client Control" onclick="javascript:__doPostBack(’Button1’, ’Button Click’);" />
</form>
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 + "<br />");
Response.Write("Arguments: " + args + "<br />");
}
}
加入
阻止asp:Button提交頁(yè)面:
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
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);
}