欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net中對(duì)象失去焦點(diǎn)時(shí)自動(dòng)提交數(shù)據(jù) V2

 更新時(shí)間:2012年11月06日 11:04:08   作者:  
一年多前,Insus.NET有寫(xiě)過(guò)一篇 《對(duì)象失去焦點(diǎn)時(shí)自己動(dòng)提交數(shù)據(jù)》,那一篇是依賴Linkbutton來(lái)做隱藏提交。是否有不用依賴Linkbutton方法呢? 答案是肯定的
.aspx頁(yè)只拉一個(gè)TextBox控件:
復(fù)制代碼 代碼如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>

.aspx.cs頁(yè)中,首選在Page_Init事件,為T(mén)extBox注冊(cè)O(shè)nBlur事件:
復(fù)制代碼 代碼如下:

protected void Page_Init(object sender, EventArgs e)
{
this.TextBox1.Attributes.Add("onblur", Page.ClientScript.GetPostBackEventReference(this.TextBox1, "OnBlur"));
}

寫(xiě)一個(gè)onBlue事件,將替代LinkButton的Click事件:
復(fù)制代碼 代碼如下:

private void OnBlurHandle(string ctrl, string args)
{
if (ctrl == this.TextBox1.UniqueID && args == "OnBlur")
{
//這里寫(xiě)提交到數(shù)據(jù)庫(kù)中
}
}

然后在網(wǎng)頁(yè)的Page_Load事件,判斷是否IsPostBack。
復(fù)制代碼 代碼如下:

protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
var ctrl = Request.Params[Page.postEventSourceID];
var args = Request.Params[Page.postEventArgumentID];
OnBlurHandle(ctrl, args);
}
}

相關(guān)文章

最新評(píng)論