对象失去焦点时自己动提交数据的实现代码

yipeiwu_com6年前PHP代码库
解决这个问题,得需要使用onblur来实现。下面代码并非是专案实现代码,只是模拟相同的功能。
复制代码 代码如下:

<!--Ajax实现页面不闪烁,一直是Insus.NET所喜欢使用的-->
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<!--放置一个TextBox,让用户输入Data-->
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<!--放置一个LinkButton,提交数据-->
<asp:LinkButton ID="LinkButton1" runat="server" Text="Submit" OnClick="LinkButton1_Click"></asp:LinkButton>
</div>
</ContentTemplate>
</asp:UpdatePanel>

.aspx.cs:
复制代码 代码如下:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class _Default : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e)
{
Data_Binding();
}
private void Data_Binding()
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
//这里写提交到数据库中
//下面是Demo使用
InsusJsUtility objJs = new InsusJsUtility();
if (string.IsNullOrEmpty(this.TextBox1.Text.Trim()))
{
objJs.JsAlert("没有数据可提交。");
return;
}
objJs.JsAlert("数据已经提交:" + this.TextBox1.Text);
}
}

上面Demo还是需要用户点击LinkButton来提交数据。为了TextBox的onblur能执行LinkButton的相同的事件,只要找到LinkButton的"__doPostBack()"。我们可以在run的页面,查看源代码:


把上面的yellow高亮的代码附加入TextBox作为onblur事件。下面代码写到.aspx.cs的Data_Binding()内。
复制代码 代码如下:

this.TextBox1.Attributes.Add("onblur", "__doPostBack('LinkButton1','')");

最后,我们需要把LinkButton的Text="Submit"改为 Text="",目的是为了把LinkButton隐藏。

相关文章

PHP利用递归函数实现无限级分类的方法

相信很多学php的很多小伙伴都会尝试做一个网上商城作为提升自己技术的一种途径。各种对商品分类,商品名之类的操作应该是得心应手,那么就可以尝试下无限级分类列表的制作了。 什么是无限级分类?...

elgg 获取文件图标地址的方法

过程如下: 首先,实体保存的时候用这个方法(系统本身的): 比如有一个Activity类,继承自ElggObject,创建了一个它的实例 activity, 复制代码 代码如下: //...

PHP 中文处理技巧

折腾了一天的时间,才弄出点眉目来。 做AJAX应用或Flash应用,提交中文内容到后台,涉及到编码解码(encode、decode)及编码格式的转换。 网上的PHP端escape une...

php修改时间格式的代码

修改时间格式: date("Y-m-d",strtotime($list['pubdate'])); 学习解释:将时间放入strtotime为时间戳后用date()转化格式.下面写了两个...

PHP正则匹配反斜杠'\'和美元'$'的方法

本文实例讲述了PHP正则匹配反斜杠'\'和美元'$'的方法。分享给大家供大家参考,具体如下: 1. test.php: <?php $content = '111111...