怎么在textbox7插入数据库前判断已存在并弹出提示框

问题描述

怎么在textbox7插入数据库前判断已存在并弹出提示框,就像下面已经写好的”用户名已存在那样“namespaceInternetShopping.AdminManage{publicpartialclassUserRegister:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){stringnum=("Server=(local);IntegratedSecurity=SSPI;database=bookshopping");SqlConnectionconnect=newSqlConnection(num);stringsql="selectcount(*)fromCustom";SqlCommandcommand=newSqlCommand(sql,connect);connect.Open();intnumcount=Convert.ToInt32(command.ExecuteScalar());numcount++;TextBox7.Text=numcount.ToString();}protectedvoidButton1_Click1(objectsender,EventArgse){stringUserName=this.TextBox1.Text;TextBox1.Text="";stringnum=("Server=(local);IntegratedSecurity=SSPI;database=bookshopping");SqlConnectionconnect=newSqlConnection(num);stringsql="select*fromCustomwherecustomName='"+UserName+"'";SqlCommandcommand=newSqlCommand(sql,connect);connect.Open();intnum1=Convert.ToInt32(command.ExecuteScalar());if(num1>0){Response.Write("<script>alert('用户名已存在');</script>");}else{SqlDataSource1.Insert();Response.Redirect("BuyComputerBooks.aspx");}connect.Close();}}}

解决方案

解决方案二:
ASHX+AJAX吧
解决方案三:
namespaceInternetShopping.AdminManage{publicpartialclassUserRegister:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){stringtxtName=TextBox7.Text;stringnum=("Server=(local);IntegratedSecurity=SSPI;database=bookshopping");SqlConnectionconnect=newSqlConnection(num);stringsql="selecttxtNamefromCustomwheretxtName="txtName";SqlCommandcommand=newSqlCommand(sql,connect);connect.Open();intnumcount=Convert.ToInt32(command.ExecuteScalar());if(numcount.length>0){Response.Write("<script>alert('用户名已存在');</script>");}}
解决方案四:
做一个光标离开事件,然后在事件中查询数据库,这是简单的,无刷新就得用ajax
解决方案五:
引用3楼qq_17634739的回复:

做一个光标离开事件,然后在事件中查询数据库,这是简单的,无刷新就得用ajax

不好意思啊,有木有什么例子额,我初学
解决方案六:
控件有个属性,mouseleave,应该是这样拼,光标重控件中离开触发的事件,你把验证写在这个里面
解决方案七:
protectedvoidButton1_Click1(objectsender,EventArgse){stringUserName=this.TextBox1.Text;TextBox1.Text="";stringnum=("Server=(local);IntegratedSecurity=SSPI;database=bookshopping");SqlConnectionconnect=newSqlConnection(num);stringsql="select*fromCustomwherecustomName='"+UserName+"'";SqlCommandcommand=newSqlCommand(sql,connect);connect.Open();intnum1=Convert.ToInt32(command.ExecuteScalar());if(num1>0){Response.Write("<script>(function(){alert('用户名已存在');})()</script>");}else{SqlDataSource1.Insert();Response.Redirect("BuyComputerBooks.aspx");}connect.Close();}

解决方案八:
引用5楼qq_17634739的回复:

控件有个属性,mouseleave,应该是这样拼,光标重控件中离开触发的事件,你把验证写在这个里面

这个事件坑爹的。。如果你的光标就没有上去过这个事件是不会触发的。。。最妥的办法就是Ajax或者直接后台保存之前校验。

时间: 2024-09-17 07:24:57

怎么在textbox7插入数据库前判断已存在并弹出提示框的相关文章

C#怎么在textbox7插入数据库前判断已存在并弹出提示框

问题描述 怎么在textbox7插入数据库前判断已存在并弹出提示框,就像下面已经写好的"用户名已存在那样"namespaceInternetShopping.AdminManage{publicpartialclassUserRegister:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){stringnum=("Server=(local);IntegratedSecurity=SSPI;

.net判断用户未登录,弹出提示“未登录,请登录”,但不加载网页

问题描述 .net判断用户未登录,弹出提示"未登录,请登录",但不加载网页要求是必须弹出提示框,提示用户需要登录,但不加载网页现在是提示了登录,就会加载网页,这样别人就能看到网页的内容用Response.End();提示框就不会弹出请高手指定哈 解决方案 解决方案二:Page.ClientScript.RegisterStartupScript(this.GetType(),"out","<script>alert('登录后再访问!');win

保存到数据库前 判断数据是否存在的问题 ,同步问题

问题描述 保存到数据库前 判断数据是否存在的问题 ,同步问题 List<GeUser> user = geUserDao.findByUserNameOrMobilePhone(m.getMobilePhone(),m.getMobilePhone()); if(user==null || user.size()==0){ geUserDao.save(m); return true; }else{ return false; 解决方案 不知道你想问什么······ 解决方案二: 保存到数据库

js 如何判断google浏览器的弹出框被拦截?

问题描述 js 如何判断google浏览器的弹出框被拦截? <br> checkwindow();<br> function checkwindow(){<br><br> var url = "../aa.aspx";<br> win = window.open(url,"","height=1px,width=1px,top=10000,left=10000,toolbar=no,menubar

怎样判断一个弹出页面是否弹出成功,或者是被拦截!请高手指点(JS代码,或者是C#代码)

问题描述 怎样判断一个弹出页面是否弹出成功,或者是被拦截!请高手指点(JS代码,或者是C#代码) 解决方案 解决方案二:自己先顶一下啦,各位大侠,高分请帮忙!解决方案三:varx=window.open('dsfsdf.html')try{if(x.title==null){alert('没有打开')}}catch{alert('没有打开')}解决方案四:在弹出前用cookie做个标记然后在弹出页里清楚这个标记用js或c#判断这个标记就知道是否弹出成功了

javascript-js 判断alert 对话框是否弹出的问题 请看下面图片

问题描述 js 判断alert 对话框是否弹出的问题 请看下面图片 这里的作用是我按一次enter键 就相当于点了一次提交按钮 现在问题来了 如果我的文本框为空 就会弹出不能为空 我连续按enter键 不能为空提示消失了 又弹出了 现在就要如果对话框是打开状态 按一下enter键 就把对话框关闭 而不是又点击提交按钮.. 解决方案 自己判断弹出层是否打开,打开就不trigger就行了 var dialogopen=false;///控制变量,如果验证不通过打开了dialog时设置dialogop

js中confirm实现执行操作前弹出确认框的方法_javascript技巧

本文实例讲述了js中confirm实现执行操作前弹出确认框的方法.分享给大家供大家参考.具体实现方法如下: 现在在删除或其它操作前弹出确定提示,我们有很多方法,最基本的就是利用js自带的函数confirm来操作了 最简单的用法如下: 鼠标事件使用confirm 复制代码 代码如下: <a href="#" onclick= "if(confirm( '是否确定! ')==false)return   false; ">点击确定</a> 想简单

jquery判断浏览器后退时候弹出消息的方法_jquery

浏览器后退时必定会有一些消息,这里使用jquery判断浏览器后退并弹出消息 jQuery(document).ready(function ($) { if (window.history && window.history.pushState) { $(window).on('popstate', function () { var hashLocation = location.hash; var hashSplit = hashLocation.split("#!/&quo

thinkPHP删除前弹出确认框的简单实现方法_php实例

本文实例讲述了thinkPHP删除前弹出确认框的简单实现方法.分享给大家供大家参考,具体如下: html部分: 复制代码 代码如下: <a href="__URL__/shanchu/id/{$vo.id}" onclick='return del();'>删除</a> javascript部分: <script> function del() { if(confirm("确定要删除吗?")) { return true; } e