如题:能否实现这样一个功能,要在输入后验证输入是否合法。
解决方案 »
- 登陆界面与sql数据库的连接出错
- gridview通过CSS固定表头出现错误,100分请教!!
- 超级郁闷!本地调试一点错都没有,上传到服务器就报500错了!
- 使用FromBase64String 提示“Base-64字符中的无效字符”这个怎么回事?
- 程序加载失败!!!dll文件不能用???是实现蓝牙功能的,好几天了都无法解决,用的是X86,网上说的方法无法解决!!!
- 日期的语法错误 在查询表达式 '#2014年2月8日星期六#' 中。
- .net2005 c#中如何将数值型转换成字符型
- 画一个矩形,怎样把现的文字,竖立起来啊,比如:内容里面,在线
- 请教C#有没有一个函数可以判断一个字符串是另一个子符串,如果是就返回true呢?
- 求c#编程问题
- HttpWebRequest 又来了……
- 一个关于WCF的问题
{
MessageBox.Show("lost focus");
//validate the value of text here
}
{
if (textBox1.Text.Length < 3)
{
errorProvider1.SetError((Control)sender, "");
textBox1.Focus(); }
else
{
errorProvider1.Clear();
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title> <script>
function CheckData()
{
var varTxt=document.getElementById("txt").value;
var s=_Default.Checka(varTxt,document.getElementById("incon").value).value;
alert(s);
}
</script></head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txt" runat="server" onblur="CheckData();"></asp:TextBox>
<input id="incon" runat="server" type="hidden" />
</form>
</body>
</html>后台:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;using MicrosoftHelper;
using System.Data.SqlClient;
public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
incon.Value = this.connStr;
Ajax.Utility.RegisterTypeForAjax(typeof(_Default));
}
[Ajax.AjaxMethod]
public string Checka(string str,string con)
{
string ss = "有";
DataSet ds = SqlHelper.ExecuteDataset(con,CommandType.Text,"select * from GW_ADNM_B where ADDVNM ='" + str + "'");
if (ds.Tables[0].Rows.Count < 1)
{
ss = "无";
}
return ss;
}
}
其中,connStr指的是数据库链接字符串
function check()
{
var a=window.document.getElementById("names").value;
//alert(a);
if(a==条件)或者用equals()
{
//alert(a);
}
alert("用户输入不正确!!");
}
</script>
<input type="text" id="names" onblur="check()">
<input type="text" id="sex">
</body>
随意输入一些数据信息,在js中写个函数,得到TextBox中的值,然后在失去焦点事件onblur跟条件去做比较。