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

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使用curl抓取qq空间的访客信息示例

config.php 复制代码 代码如下:<?phpdefine('APP_DIR', dirname(__FILE__));define('COOKIE_FILE', APP_D...

php下使用curl模拟用户登陆的代码

bool curl_setopt (int ch, string option, mixed value) curl_setopt()函数将为一个CURL会话设置选项。option参数是...

PHP中输出转义JavaScript代码的实现代码

分享一下: 复制代码 代码如下: function jsformat($str) { $str = trim($str); $str = str_replace('\\s\\s', '\...

PHP编程实现多维数组按照某个键值排序的方法小结【2种方法】

PHP编程实现多维数组按照某个键值排序的方法小结【2种方法】

本文实例讲述了PHP编程实现多维数组按照某个键值排序的方法。分享给大家供大家参考,具体如下: 实现对多维数组按照某个键值排序的两种解决方法(array_multisort和array_s...

PHP屏蔽过滤指定关键字的方法

本文实例讲述了PHP屏蔽过滤指定关键字的方法。分享给大家供大家参考。具体分析如下: 实现思路: 一、把关键字专门写在一个文本文件里,每行一个,数量不限,有多少写多少。 二、PHP读取关键...