Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

[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;
    }
Posted
Comments
Karthik_Mahalingam 20-Mar-17 2:55am    
is the ajax call hitting the web method?
心心傷心 20-Mar-17 3:04am    
no, it is not working..
Karthik_Mahalingam 20-Mar-17 3:09am    
check the console window for any errors ?
https://developers.google.com/web/tools/chrome-devtools/console/
心心傷心 20-Mar-17 4:19am    
i dont know how
Karthik_Mahalingam 20-Mar-17 6:48am    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900