asp.net中对象失去焦点时自动提交数据 V2

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了asp.net中对象失去焦点时自动提交数据 V2脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
.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注册OnBlur事件:
复制代码 代码如下:

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")
{
//这里写提交到数据库
}
}

然后在网页的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);
}
}

脚本宝典总结

以上是脚本宝典为你收集整理的asp.net中对象失去焦点时自动提交数据 V2全部内容,希望文章能够帮你解决asp.net中对象失去焦点时自动提交数据 V2所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:失去焦点