本文介绍了如何使用ASP.NET中的引导验证程序从数据库验证用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 I want to validate a username from database using bootstrap validator in asp.net. This is some code i tried but not working... When i put remote, the username field is always invalid. Is this correct way to do so? 我尝试过: What I have tried:<pre>username: { validators: { remote: { url: '/Registration.aspx/CheckUsername', type:'POST', data: '{user: "' + $("#<%=username.ClientID%>")[0].value + '" }', message: 'The username is not available.', }, notEmpty: { message: 'Please fill in your username.' } } }, ---- backend ----backend [System.Web.Services.WebMethod] public static string CheckUsername(string user) { string retval = ""; SqlConnection bbmsConn; string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; bbmsConn = new SqlConnection(connStr); bbmsConn.Open(); SqlCommand cmd = new SqlCommand("select username from Accounts where username=@username", bbmsConn); cmd.Parameters.AddWithValue("@username", user); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { retval = "true"; } else { retval = "false"; } return retval; } 推荐答案 (#<%= username.ClientID%>)[0] .value + ''}',消息:'用户名不可用。', }, notEmpty:{ message:'请填写您的用户名。 '} } },("#<%=username.ClientID%>")[0].value + '" }', message: 'The username is not available.', }, notEmpty: { message: 'Please fill in your username.' } } }, ---- backend ----backend [System.Web.Services.WebMethod] public static string CheckUsername(string user) { string retval = ""; SqlConnection bbmsConn; string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; bbmsConn = new SqlConnection(connStr); bbmsConn.Open(); SqlCommand cmd = new SqlCommand("select username from Accounts where username=@username", bbmsConn); cmd.Parameters.AddWithValue("@username", user); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { retval = "true"; } else { retval = "false"; } return retval; } 这篇关于如何使用ASP.NET中的引导验证程序从数据库验证用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-30 15:28