Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck if username exists in a asp.net form
    text
    copied!<p>I am currently creating a registration form in asp.net and c#. What I want to be able to do is to allow the user to enter a username, when they remove focus from the text box it checks a mysql database to see if the username exists or not. If it does then a css container is shown to inform the user that the username has already been taken. </p> <p>I have tried to use Javascript/JQuery to hide the CSS container which is working fine. My plan was to run the textchanged event on the text box and then if this function returned true would then use javascript/jquery to reshow the css container. However, I found that to use the text changed event I needed to enable autopostback on the field which also meant that the form refreshed and tried to submit the form therefore stopping my plan from working.</p> <p><strong>EDIT</strong> In response to sfomate about using the update panel. I have tried this method using the following code segment from the form</p> <pre><code> &lt;asp:ScriptManager ID="scriptManager" runat="server" /&gt; &lt;asp:UpdatePanel runat="server" ID="userUpdate" UpdateMode="Conditional"&gt; &lt;Triggers&gt; &lt;asp:AsyncPostBackTrigger ControlID="txtUsername" EventName="TextChanged" /&gt; &lt;/Triggers&gt; &lt;ContentTemplate&gt; &lt;asp:TextBox id="txtUsername" TextMode="SingleLine" required placeholder="Username" runat="server" ontextchanged="txtUsername_TextChanged" AutoPostBack="True" /&gt; &lt;span class="tooltip"&gt;Please enter your username&lt;/span&gt; &lt;span class="fieldExists"&gt;Username exists&lt;/span&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; </code></pre> <p>This is stopping the auto post back of the whole pagewhen the text box loses focus using the text changed event. However, nothing is added to the page with the Response.Write() code I have added. I have tried to just print hello world or show the css container using Javascript but nothing seems to show up straight after the text box losing focus. However, when I click the submit button the response.write() is then shown which is not what I want. </p> <p>Thanks for your help. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload