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?
<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.' } } },
[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; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)