在TextBox1输完值后,判断该数值是否存在,如果存在,则把TextBox1的Text值设为空,让TextBox 1得到焦点。 在TextBox1的TextChanged事件中来判断该值是否存在,如果存在,则显示该值已存在,并让TextBox1得到焦点,让用户重新输入;如果不存在,则不显示任何信息,让用户继续输入其他控件的值。我该这样写代码?代码的调用怎么调用?在线等,谢谢大家。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把textbox的post熟悉设置为ture,这样就可以相应TextChanged事件了,事件内容直接写到TextChanged的相应函数里就可以了 private void textBox1_TextChanged(object sender, System.EventArgs e){ if(true) { textBox1.Text = ""; textBox1.Focus(); } else { MessageBox.Show("此字符串不存在!"); }} private void textBox1_TextChanged(object sender, System.EventArgs e){ if( 存在 == true ) { textBox1.Text = ""; textBox1.Focus(); } else { MessageBox.Show("此字符串不存在!"); }} 我的理解是不是搂主想知道用户输入的数据(用户名在数据库中存在吗?)存在就提示用户,不存在就接着添加。这个要用js来实现,用xmlhttp:var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//下面是post到检查页面(注意检查页只能有程序不能有html)xmlhttp.open("POST","check.aspx?a="+escape(parmSignContractNumber)+"&b="+escape(parmSignPeople)+"&c="+escape(parmCID)+"&d="+parmSignContractId+"&e="+parmContract_type_id, false);xmlhttp.send();var result; result= bytes2BSTR(xmlhttp.responseBody);xmlhttp = null;if(result=="ok"){return true;}else{false;}函数:<script language="VBscript">Function bytes2BSTR(vIn)dim strReturndim i,ThisCharCode,NextCharCodestrReturn = ""For i = 1 To LenB(vIn)ThisCharCode = AscB(MidB(vIn,i,1))If ThisCharCode < &H80 ThenstrReturn = strReturn & Chr(ThisCharCode)ElseNextCharCode = AscB(MidB(vIn,i+1,1))strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))i = i + 1End IfNextbytes2BSTR = strReturnEnd Function</script>***************check.aspx(检查页)******************.cs文件: a = Request.QueryString["a"].Trim(); b = Convert.ToInt32(Request.QueryString["b"].Trim()); c = Convert.ToInt32(Request.QueryString["c"].Trim()); d = Request.QueryString["d"].Trim(); g = Convert.ToInt32(Request.QueryString["e"].Trim()); string strSql,strSql2,strSql3; int intCount,intCount2,intCount3; conn.dbOpen(); strSql="" SqlCommand cmd=new SqlCommand(strSql,conn.myCn); intCount=(int)cmd.ExecuteScalar(); strSql2=""; SqlCommand cmd1=new SqlCommand(strSql2,conn.myCn); intCount2=(int)cmd1.ExecuteScalar(); strSql3=""; SqlCommand cmd2=new SqlCommand(strSql3,conn.myCn); intCount3=(int)cmd2.ExecuteScalar(); conn.dbClose(); if(intCount>0 && intCount2==0 && intCount3==1) { f = "ok"; } else { if(intCount<=0) { f = "no2"; } else { if(intCount2>0) { f = "no1"; } else { if(intCount3<1) { f = "no"; } } } } } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); }**********************************************************************这是关键重写Render事件,返回状态值********************************************************************** protected override void Render(HtmlTextWriter output) { output.Write(f); } #endregion******************************************************************************************************.aspx文件什么都不能存在。 楼主说的不清楚,使用ExecuteScalar()方法,看返回的值就是了不过注意ExecuteScalar()返回的是object,需要转换的 UTC的时间怎么得到 将gridview导出成excel表格时可不可以将编辑和删除这两列不导出来 问一个树查询的问题 .net读取全局变量问题 请教向存储过程传递参数但没有成功,请指教 请大家帮忙 asp 程序 在windows2003 server 下能运行吗? 求解 自定义datagrid的更新和删除,大家一起讨论一下,分不够再加。 aspx页面无法运行,aspx文件编译后的警告:运行时错误,未将对象引用设置到对象实例 如何做到不通过web.config来控制上传文件的大小 关于水晶报表中参数的问题 求助 数据库插记录的问题
事件内容直接写到TextChanged的相应函数里就可以了
{
if(true)
{
textBox1.Text = "";
textBox1.Focus();
}
else
{
MessageBox.Show("此字符串不存在!");
}
}
{
if( 存在 == true )
{
textBox1.Text = "";
textBox1.Focus();
}
else
{
MessageBox.Show("此字符串不存在!");
}
}
这个要用js来实现,用xmlhttp:
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//下面是post到检查页面(注意检查页只能有程序不能有html)
xmlhttp.open("POST","check.aspx?a="+escape(parmSignContractNumber)+"&b="+escape(parmSignPeople)+"&c="+escape(parmCID)+"&d="+parmSignContractId+"&e="+parmContract_type_id, false);
xmlhttp.send();
var result;
result= bytes2BSTR(xmlhttp.responseBody);
xmlhttp = null;
if(result=="ok")
{
return true;
}
else
{
false;
}
函数:
<script language="VBscript">
Function bytes2BSTR(vIn)
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
</script>
***************
check.aspx(检查页)
******************
.cs文件:
a = Request.QueryString["a"].Trim();
b = Convert.ToInt32(Request.QueryString["b"].Trim());
c = Convert.ToInt32(Request.QueryString["c"].Trim());
d = Request.QueryString["d"].Trim();
g = Convert.ToInt32(Request.QueryString["e"].Trim());
string strSql,strSql2,strSql3;
int intCount,intCount2,intCount3;
conn.dbOpen();
strSql=""
SqlCommand cmd=new SqlCommand(strSql,conn.myCn);
intCount=(int)cmd.ExecuteScalar();
strSql2="";
SqlCommand cmd1=new SqlCommand(strSql2,conn.myCn);
intCount2=(int)cmd1.ExecuteScalar();
strSql3="";
SqlCommand cmd2=new SqlCommand(strSql3,conn.myCn);
intCount3=(int)cmd2.ExecuteScalar();
conn.dbClose();
if(intCount>0 && intCount2==0 && intCount3==1)
{
f = "ok";
}
else
{
if(intCount<=0)
{
f = "no2";
}
else
{
if(intCount2>0)
{
f = "no1";
}
else
{
if(intCount3<1)
{
f = "no";
}
}
}
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
**********************************************************************
这是关键重写Render事件,返回状态值
**********************************************************************
protected override void Render(HtmlTextWriter output)
{
output.Write(f);
}
#endregion
**************************************************************************
****************************
.aspx文件什么都不能存在。
不过注意ExecuteScalar()返回的是object,需要转换的