asp.net中對象失去焦點(diǎn)時自動提交數(shù)據(jù) V2
更新時間:2012年11月06日 11:04:08 作者:
一年多前,Insus.NET有寫過一篇 《對象失去焦點(diǎn)時自己動提交數(shù)據(jù)》,那一篇是依賴Linkbutton來做隱藏提交。是否有不用依賴Linkbutton方法呢? 答案是肯定的
.aspx頁只拉一個TextBox控件:
<%@ 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頁中,首選在Page_Init事件,為TextBox注冊O(shè)nBlur事件:
protected void Page_Init(object sender, EventArgs e)
{
this.TextBox1.Attributes.Add("onblur", Page.ClientScript.GetPostBackEventReference(this.TextBox1, "OnBlur"));
}
寫一個onBlue事件,將替代LinkButton的Click事件:
private void OnBlurHandle(string ctrl, string args)
{
if (ctrl == this.TextBox1.UniqueID && args == "OnBlur")
{
//這里寫提交到數(shù)據(jù)庫中
}
}
然后在網(wǎng)頁的Page_Load事件,判斷是否IsPostBack。
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);
}
}
復(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頁中,首選在Page_Init事件,為TextBox注冊O(shè)nBlur事件:
復(fù)制代碼 代碼如下:
protected void Page_Init(object sender, EventArgs e)
{
this.TextBox1.Attributes.Add("onblur", Page.ClientScript.GetPostBackEventReference(this.TextBox1, "OnBlur"));
}
寫一個onBlue事件,將替代LinkButton的Click事件:
復(fù)制代碼 代碼如下:
private void OnBlurHandle(string ctrl, string args)
{
if (ctrl == this.TextBox1.UniqueID && args == "OnBlur")
{
//這里寫提交到數(shù)據(jù)庫中
}
}
然后在網(wǎng)頁的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)文章
使用ASP.NET.4.5.1+MVC5.0 搭建一個包含 Ninject框架 項(xiàng)目
這篇文章主要介紹了使用ASP.NET.4.5.1+MVC5.0 搭建一個包含 Ninject框架 項(xiàng)目的方法,需要的朋友可以參考下2015-01-01
.NetCore使用MailKit發(fā)送和接收郵件的方法
MailKit是一個開源的.NET庫,提供了對SMTP、POP3和IMAP的訪問,使得發(fā)送和接收電子郵件變得簡單,下面是一個基本的示例,展示了如何使用MailKit來發(fā)送和接收郵件,感興趣的朋友跟隨小編一起看看吧2024-07-07
ASP.NET?Core?實(shí)現(xiàn)自動刷新JWT?Token
這篇文章主要介紹了ASP.NET?Core?實(shí)現(xiàn)自動刷新JWT?Token,通過增加??refresh_token??,客戶端使用refresh_token去主動刷新JWT?Token,下文具體操作過程需要的小伙伴可以參考一下2022-04-04
獲取ashx得到的內(nèi)容(已處理好的數(shù)據(jù))
獲取ashx得到的內(nèi)容,一般用于ajax的情況比較多一點(diǎn);重點(diǎn):ashx頁面?zhèn)鬟^來的就是已經(jīng)處理好的數(shù)據(jù),感興趣的朋有可以參考下啊,希望本文對你學(xué)習(xí)ajax有所幫助2013-01-01
aspnet_isapi.dll設(shè)置圖文方法.net程序?qū)崿F(xiàn)偽靜態(tài)
aspnet_isapi.dll設(shè)置圖文介紹.net的程序?qū)崿F(xiàn)偽靜態(tài),需要的朋友可以參考下。2009-11-11

