title: How to cancel sending data while the username is taken
body: <p>When someone fills out my registration form and the username is taken, it refreshes the page and says "The username is taken, choose another".</p>
  
  <p>But all the data that the person filled in is removed.</p>
  
  <p>How can I stop the refreshing if the username is taken, so the user can just change it?</p>
  
  <pre><code>protected string msg = "";
  protected void Page_Load(object sender, EventArgs e)
  {
      if (this.IsPostBack)
      {
          string FirstName = Request.Form["FirstName"];
          string LastName = Request.Form["LastName"];
          string PhoneNumber = Request.Form["PhoneNumber"];
          string Prefix = Request.Form["Prefix"];
          PhoneNumber = Prefix + PhoneNumber;
          int BirthYear = int.Parse(Request.Form["BirthYear"]);
          string Email = Request.Form["Email"];
          string UserName = Request.Form["UserName"];
          string Password = Request.Form["Password"];
          string gender = Request.Form["gender"];
          string dbPath = this.MapPath("App_Data/Database.mdf");
          DAL dal = new DAL(dbPath);
          UtilityUser uu = new UtilityUser(dal);
          if (uu.Exist(UserName))
          {
              msg = "שם המשתמש שבחרת תפוס"; **//username is taken**
          }
          else
          {
              uu.Register(FirstName, LastName, PhoneNumber, BirthYear, Email, UserName, Password, gender);
              msg = "נרשמת בהצלחה!"; **// Register succeed**
          }
      }
  }
  </code></pre>
  
  <p>This is the form to check for username:</p>
  
  <pre><code>var UserName = aspnetForm.UserName.value;
      if (UserName.length &lt; 6) {
          document.getElementById("labelUserName").innerHTML = '&lt;img src=\'images/X.png\'&gt;'; //**X icon**
          Fields += "שם משתמש - שדה זה חייב להכיל בין 6 ל־12 תווים\n";
          correct = false;
      }
      else {
          document.getElementById("labelUserName").innerHTML = '&lt;img src=\'images/V.png\'&gt;'; //**V icon**
      }
  </code></pre>