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 in Page Load and keyup based on TextBox value using AJAX PageMethods in ASP.NetHi @power,<br />Please try the following<br /><br /><a href = 'link(Threads/629201/Check-whether-username-exists-in-database-in-ASPNet/)'>Check whether username exists in database in ASP.Net</a><br /><br />It might help you.<br /><br />Cheers Andrea.https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/Thu, 10 Aug 2017 21:56:03 GMTCheck Username availability in Page Load and keyup based on TextBox value using AJAX PageMethods in ASP.Net<p>Hi Andrea, I already tried the link you provided me but didn't help. Please take a good look at my question.&nbsp;</p>https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/Thu, 10 Aug 2017 23:31:00 GMTCheck Username availability in Page Load and keyup based on TextBox value using AJAX PageMethods in ASP.Net<p>Hi <a class="username" rel="power">power</a>,</p> <p>I have created sample code which full-fill your requirement. So please refer the below code and modify as per your requirement.</p> <p><span style="text-decoration: underline;">HTML</span></p> <pre class="brush: html">&lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;div&gt; &lt;asp:ScriptManager ID=&#34;ScriptManager1&#34; runat=&#34;server&#34; EnablePageMethods=&#34;true&#34;&gt; &lt;/asp:ScriptManager&gt; &lt;asp:TextBox ID=&#34;txtUsername&#34; onChange=&#34;Username_OnChange(this)&#34; onkeyup=&#34;keyupfunction(this)&#34; runat=&#34;server&#34; /&gt; &lt;span id=&#34;Username_Check&#34;&gt;&lt;/span&gt; &lt;/div&gt; &lt;div&gt; &lt;script type=&#34;text/javascript&#34;&gt; function UsernameAvailability(name) { PageMethods.CheckUserName(name, Username_OnSuccess); } function Username_OnSuccess(response) { var mesg = document.getElementById(&#34;Username_Check&#34;); switch (response) { case &#34;true&#34;: mesg.style.color = &#34;&#34;; mesg.innerHTML = &#34;&#34;; break; case &#34;false&#34;: mesg.style.color = &#34;red&#34;; mesg.innerHTML = &#34;Username already taken.&#34;; break; } } function Username_OnChange(txt) { document.getElementById(&#34;Username_Check&#34;).innerHTML = &#34;&#34;; var mesg = document.getElementById(&#34;Username_Check&#34;); mesg.innerHTML = &#34;&#34;; } function keyupfunction(d) { UsernameAvailability(d.value) } &lt;/script&gt; &lt;/div&gt; &lt;/form&gt;</pre> <p><span style="text-decoration: underline;">C#</span></p> <pre class="brush: csharp">[System.Web.Services.WebMethod()] public static string CheckUserName(string userName) { string returnValue = string.Empty; try { string consString = ConfigurationManager.ConnectionStrings[&#34;conString&#34;].ConnectionString; SqlConnection conn = new SqlConnection(consString); SqlCommand cmd = new SqlCommand(&#34;CheckUsername&#34;, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(&#34;@Username&#34;, userName.Trim()); conn.Open(); returnValue = cmd.ExecuteScalar().ToString(); conn.Close(); } catch { returnValue = &#34;error&#34;; } return returnValue; }</pre> <p><span style="text-decoration: underline;">Vb.Net</span></p> <pre class="brush: vb"> &lt;System.Web.Services.WebMethod()&gt; _ Public Shared Function CheckUserName(ByVal userName As String) As String Dim returnValue As String = String.Empty Try Dim consString As String = ConfigurationManager.ConnectionStrings(&#34;ConString&#34;).ConnectionString Dim conn As New SqlConnection(consString) Dim cmd As New SqlCommand(&#34;CheckUsername&#34;, conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue(&#34;@Username&#34;, userName.Trim()) conn.Open() returnValue = cmd.ExecuteScalar().ToString() conn.Close() Catch returnValue = &#34;error&#34; End Try Return returnValue End Function</pre> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/Fri, 11 Aug 2017 03:15:28 GMTCheck Username availability in Page Load and keyup based on TextBox value using AJAX PageMethods in ASP.Net<p>Hello Indresh,</p> <p>Thank you for your sample. I adjusted few things to meet my requirement, however, it didn't help me at all. Did you try your sample at all and did it work for you? My original question was based on one of the sample examples written by Mudassar. If possible could you ask him to look at my original question since my question is identical to his sample?</p> <p>Thank you.&nbsp;</p>https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/Fri, 11 Aug 2017 10:45:53 GMTCheck Username availability in Page Load and keyup based on TextBox value using AJAX PageMethods in ASP.Net<p>Hi <a class="username" rel="power">power</a>,</p> <p>Check the parameter you have passed.</p> <p>In procedure you are passing @Email as parameter and in code behind you have used @Username as parameter. Thats the wrong you are doing.</p>https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/Mon, 14 Aug 2017 04:22:51 GMTCheck Username availability in Page Load and keyup based on TextBox value using AJAX PageMethods in ASP.Net<p>Thank you for catching my mistake. I must have been blinded by something.... The thing is yesterday I caught the mistake I made in the procedure and corrected it to @Username but then I realized that I had other mistake and I want to tell you guys because it might help others from making similar mistake. I tried to use updatepanel with webpages and this two don't work together. Then I removed the updatepanel and it starts to work well. The issue I have now is the page flickers because I removed updatepanel. How do i prevent page flickering when I click submit button without updatepanel? Thanks.</p>https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/Mon, 14 Aug 2017 05:24:29 GMTCheck Username availability in Page Load and keyup based on TextBox value using AJAX PageMethods in ASP.Net<p>I have checked the code by putting the controls inside update panel. Its working. So if you have the error please provide screenshot.</p>https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/Mon, 14 Aug 2017 08:49:05 GMTCheck Username availability in Page Load and keyup based on TextBox value using AJAX PageMethods in ASP.Net<p>The onkeyup event is what is giving me issue. When the page initialy loads, the stored procedure doesn't detect if the username is already taken. The stored procedure starts to work if I first clicked the submit button. It is confussing me why it is doing that.&nbsp;</p> <p>I guess my question should be what is the correct way to make the stored procedure work when the page initially loads so the stored procedure detects the useranme textbox even at the initial page load? I amasking this because currently the stored procedure doesn't work when the pages initialy loads.</p>https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/Mon, 14 Aug 2017 11:21:38 GMTCheck Username availability in Page Load and keyup based on TextBox value using AJAX PageMethods in ASP.Net<p>Hi <a class="username" rel="power"> power</a>,</p> <p>You need to add the below line of code inside the script. So when the palod finish it will check the UserName availability based on the TextBox value.</p> <pre class="brush: js">window.onload = function UsernameAvailability() { PageMethods.CheckUserName(document.getElementById(&#34;&lt;%=txtUsername.ClientID%&gt;&#34;).value, Username_OnSuccess); }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/Wed, 16 Aug 2017 03:39:35 GMTCheck Username availability in Page Load and keyup based on TextBox value using AJAX PageMethods in ASP.Net<p>Hi dharmendr,</p> <p>Thank you so much for your help. You have been a great help in the past as well. The good news is the solution you provided me actually solved half of my problem. Just like you said I added the code into the script and then whenever the page loads it keeps the txtUsername value and automatically activates the stored procedure. In the past, it never automatically activates the stored procedure on page load/refresh. So that part is solved. However, the issue I still have is I still have to enter value in the txtUsername and then click the submit button. Only then the stored procedure gets activated.</p> <p>But what I want is the stored procedure to be active even when you first browse and the website opens for the first time. Then you type a name in the txtUsername textbox and if similar name exists in database, the &lt;span id="Username_Check"&gt; automatically displays the message &ldquo;Username already taken.&rdquo; without clicking the Submit button. That is the problem I couldn&rsquo;t solve. I tried to change the onkeyup attribute to oninput but no luck. The only way it works right now is if I enter the name into the textbox and then click the submit button. But I want it to detect without clicking the button. &nbsp;Hope you better understand my issue now. You already solved half the problem!</p> <p>Thank you in advance for your help</p>https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/Wed, 16 Aug 2017 19:38:12 GMTCheck Username availability in Page Load and keyup based on TextBox value using AJAX PageMethods in ASP.Net<p>Hi <a class="username" rel="power"> power</a>,</p> <p>Here i have created complete sample. Refer the below code.</p> <p><span style="text-decoration: underline;">HTML</span></p> <pre class="brush: html">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;&lt;/title&gt; &lt;script type=&#34;text/javascript&#34;&gt; window.onload = function Test() { PageMethods.CheckUserName(document.getElementById(&#34;&lt;%=txtUsername.ClientID%&gt;&#34;).value, Username_OnSuccess); } function UsernameAvailability() { PageMethods.CheckUserName(document.getElementById(&#34;&lt;%=txtUsername.ClientID%&gt;&#34;).value, Username_OnSuccess); } function Username_OnSuccess(response) { var mesg = document.getElementById(&#34;Username_Check&#34;); if (document.getElementById(&#34;&lt;%=txtUsername.ClientID%&gt;&#34;).value.length &gt; 0) { switch (response) { case &#34;true&#34;: mesg.style.color = &#34;green&#34;; mesg.innerHTML = &#34;Available&#34;; break; case &#34;false&#34;: mesg.style.color = &#34;red&#34;; mesg.innerHTML = &#34;Username already taken.&#34;; break; } } else { mesg.innerHTML = &#34;&#34;; } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;div&gt; &lt;asp:ScriptManager ID=&#34;ScriptManager1&#34; runat=&#34;server&#34; EnablePageMethods=&#34;true&#34;&gt; &lt;/asp:ScriptManager&gt; &lt;asp:UpdatePanel runat=&#34;server&#34;&gt; &lt;ContentTemplate&gt; &lt;asp:TextBox ID=&#34;txtUsername&#34; onChange=&#34;UsernameAvailability()&#34; onkeyup=&#34;UsernameAvailability()&#34; ondrop=&#34;return false;&#34; onpaste=&#34;return false;&#34; runat=&#34;server&#34; Text=&#34;maria&#34; /&gt; &lt;span id=&#34;Username_Check&#34;&gt;&lt;/span&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><span style="text-decoration: underline;">C#</span></p> <pre class="brush: csharp">[System.Web.Services.WebMethod()] public static string CheckUserName(string userName) { string returnValue = string.Empty; try { string consString = ConfigurationManager.ConnectionStrings[&#34;conString&#34;].ConnectionString; SqlConnection conn = new SqlConnection(consString); SqlCommand cmd = new SqlCommand(&#34;CheckUsername&#34;, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(&#34;@Name&#34;, userName.Trim()); conn.Open(); returnValue = cmd.ExecuteScalar().ToString(); conn.Close(); } catch (Exception ex) { returnValue = &#34;error&#34;; } return returnValue; }</pre> <p><span style="text-decoration: underline;">VB.Net</span></p> <pre class="brush: vb">&lt;System.Web.Services.WebMethod()&gt; _ Public Shared Function CheckUserName(ByVal userName As String) As String Dim returnValue As String = String.Empty Try Dim consString As String = ConfigurationManager.ConnectionStrings(&#34;ConString&#34;).ConnectionString Dim conn As New SqlConnection(consString) Dim cmd As New SqlCommand(&#34;CheckUsername&#34;, conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue(&#34;@Name&#34;, userName.Trim()) conn.Open() returnValue = cmd.ExecuteScalar().ToString() conn.Close() Catch returnValue = &#34;error&#34; End Try Return returnValue End Function</pre> <p><span style="text-decoration: underline;">Screenshot</span></p> <p><span style="text-decoration: underline;"><img src="http://i.imgur.com/H0vHMqY.gif" alt="" width="326" height="98" /></span></p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/https://www.aspforums.net:443/Threads/603372/Check-Username-availability-in-Page-Load-and-keyup-based-on-TextBox-value-using-AJAX-PageMethods-in-ASPNet/Thu, 17 Aug 2017 06:44:53 GMT