ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Check Username availability using jQuery AJAX and WebService in ASP.Net<p>Hi <a class="username" rel="pooya1072"> pooya1072</a>,</p> <p>The speed depends on the query result, network speed, server speed and the processor.</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js&#34;&gt;&lt;/script&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(document).ready(function () { document.getElementById(&#34;txtUserName&#34;).onkeyup = function () { var userName = document.getElementById(&#34;txtUserName&#34;).value; var divElement = document.getElementById(&#39;label&#39;) if (userName.length &gt;= 3) { jQuery.ajax({ url: &#39;RegisterationService.asmx/UserNameExists&#39;, type: &#39;POST&#39;, data: &#34;{ userName: &#39;&#34; + userName + &#34;&#39;}&#34;, dataType: &#39;json&#39;, contentType: &#34;application/json; charset=utf-8&#34;, success: function (data) { if (data.d) { document.getElementById(&#39;label&#39;).innerHTML = userName + &#39; is in Used&#39; document.getElementById(&#39;label&#39;).style.color = &#39;red&#39; document.getElementById(&#34;txtUserName&#34;).style.borderColor = &#34;red&#34; } else { document.getElementById(&#39;label&#39;).innerHTML = userName + &#39; is available&#39; document.getElementById(&#39;label&#39;).style.color = &#39;green&#39; } }, error: function (err) { alert(err); } }); } else { document.getElementById(&#39;label&#39;).innerHTML = &#39;&#39; document.getElementById(&#34;txtUserName&#34;).style.borderColor = &#34;&#34; } } }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input id=&#34;txtUserName&#34; style=&#34;width: 50%&#34; type=&#34;text&#34; /&gt; &lt;br /&gt; &lt;div style=&#34;height: 30px; width: 50%;&#34;&gt; &lt;label id=&#34;label&#34;&gt; &lt;/label&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Web.Services; using System.Data.SqlClient; using System.Configuration; using System.Data;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Data.SqlClient Imports System.Data</pre> <p><span style="text-decoration: underline;"><strong>Code (asmx WebService)</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">[WebMethod] public bool UserNameExists(string userName) { string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;SELECT Name FROM Customers WHERE Name = @Name&#34;, con)) { cmd.Parameters.AddWithValue(&#34;@Name&#34;, userName); using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { DataTable dt = new DataTable(); da.Fill(dt); return dt.Rows.Count &gt; 0 ? true : false; } } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">&lt;WebMethod()&gt; Public Function UserNameExists(ByVal userName As String) As Boolean Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Using con As SqlConnection = New SqlConnection(constr) Using cmd As SqlCommand = New SqlCommand(&#34;SELECT Name FROM Customers WHERE Name = @Name&#34;, con) cmd.Parameters.AddWithValue(&#34;@Name&#34;, userName) Using da As SqlDataAdapter = New SqlDataAdapter(cmd) Dim dt As DataTable = New DataTable() da.Fill(dt) Return If(dt.Rows.Count &gt; 0, True, False) End Using End Using End Using End Function</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/gdj7o0U.gif" alt="" width="245" height="170" /></p>https://www.aspforums.net:443/Threads/131477/Check-Username-availability-using-jQuery-AJAX-and-WebService-in-ASPNet/https://www.aspforums.net:443/Threads/131477/Check-Username-availability-using-jQuery-AJAX-and-WebService-in-ASPNet/Wed, 15 Aug 2018 05:14:53 GMT