title: ASP Web Forms : Text box is retaining old values in post back
body: <p>I have 2 <code>text boxes</code> with <code>compare validator</code> controls . But at postback ,the <code>textbox</code> values are appended by comma. And on edit mode new value is appended by comma followed by previous value. </p>
  
  <p>Create Mode
  <a href="https://i.stack.imgur.com/j2F6n.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/j2F6n.jpg" alt=""></a></p>
  
  <p>Edit Mode 
  <a href="https://i.stack.imgur.com/hKQyw.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/hKQyw.jpg" alt="At Edit mode"></a></p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
      {
  
  
          if (!IsPostBack)
          {
              lblClientName.Text = "" + Request.QueryString["clientname"];
              BindAddressSheet();           
              string addrShtId = "" + Request.QueryString["addrshtid"];
              hdnAddrSheetId.Value = addrShtId;               
              if (hdnAddrSheetId.Value!=String.Empty)
              {                
                  FillAddressDetails();  //load values on edit mode              
  
              }            
  
          }
      }
   public void FillAddressDetails()
      {
          string addrShtId = "" + Request.QueryString["addrshtid"];
  
          AddrShtBOL objBOL = new AddrShtBOL();
          AddrShtBAL objBAL = new AddrShtBAL();
  
          objBOL = objBAL.SelectAddressSheetByID(Util.ToInt(addrShtId));
          // the following 2 text boxes retain the values
          txtHzntalPostn.Text = objBOL.AddrshtHpos.ToString();
          txtVertPostn.Text = objBOL.AddrshtVpos.ToString();
          ddlOrientation.SelectedValue = objBOL.AddrshtOrient;
          ddlUnitOfMeasure.SelectedValue = objBOL.AddrshtPosUnits;
          txtLogoHzntalPostn.Text = objBOL.AddrshtLogoHpos.ToString();
          txtLogoVertPostn.Text = objBOL.AddrshtLogoVpos.ToString();
          txtLogoName.Text = objBOL.AddrshtLogoNm;
          txtAddr1.Text = objBOL.AddrshtRetnAddrIn1;
          txtAddr2.Text = objBOL.AddrshtRetnAddrIn2;
          txtAddr3.Text = objBOL.AddrshtRetnAddrIn3;
          txtAddr4.Text = objBOL.AddrshtRetnAddrIn4;
          txtAddr5.Text = objBOL.AddrshtRetnAddrIn5;
          txtAddr6.Text = objBOL.AddrshtRetnAddrIn6;
          txtRtnAddHzntalPostn.Text = objBOL.AddrshtRetnShtHpos.ToString();
          txtRtnAddVertPostn.Text = objBOL.AddrshtRetnShtVpos.ToString();      
  
      }
   //Button click event 
   protected void btnSaveAddSheets_Click(object sender, EventArgs e)
      {
          if (txtHzntalPostn.Text.Trim() == "")
          {
              ShowMessage("Please enter Horizontal Position");
              txtHzntalPostn.Focus();
              return;
          }
          if (txtVertPostn.Text.Trim() == "")
          {
              ShowMessage("Please enter Vertical Position");
              txtVertPostn.Focus();
              return;
          }
  
          AddrShtBOL BOL = new AddrShtBOL();
          AddrShtBAL BAL = new AddrShtBAL();
          string clientNo = "" + Request.QueryString["clientno"];
  
          BOL.OmAddrShtId = Util.ToInt(hdnAddrSheetId.Value);
  
          if (BOL.OmAddrShtId &gt; 0)
          {
              BOL.Action = 4;
          }
          else
          {
              BOL.Action = 1;
          }
          BOL.ClientNo = clientNo;
          BOL.AddrShtFmtCd = 0;// addrShtFmtCd;
          BOL.AddrshtHpos = Util.ToDecimal(txtHzntalPostn.Text.Trim());
          BOL.AddrshtVpos = Util.ToDecimal(txtVertPostn.Text.Trim());
          BOL.AddrshtOrient = ddlOrientation.SelectedValue;
          BOL.AddrshtPosUnits = ddlUnitOfMeasure.SelectedValue;
          BOL.CreatedBy = "" + Request.ServerVariables["LOGON_USER"];
          int result = BAL.InsertAddressSheet(BOL);
  
          hdnAddrSheetId.Value = result.ToString();
  
          if (result &gt; 0)
          {
              lblAddr.Text = "Address Sheet details saved";
  
              BindAddressSheet();          
  
          }
          if (BOL.Action == 1)
          {
              hdnAddrSheetId.Value = result.ToString();
              lblErr.Visible = false;
          }
  
      }
  </code></pre>
  
  <p>Client Side </p>
  
  <pre><code> &lt;div class="form-group col-md-4 col-sm-6"&gt;
   &lt;label for="description"&gt;
   H. Pos&lt;/label&gt;
   &lt;asp:TextBox ID="txtHzntalPostn" runat="server" CssClass="form-control" MaxLength="7"placeholder="0"&gt; &lt;/asp:TextBox&gt;                        
  &lt;asp:CompareValidator ID="cmp1" runat="server" ErrorMessage=" &lt;= 999.999" ControlToValidate="txtHzntalPostn"Operator="LessThan" Type="Double" ValueToCompare="1000" Style="font-size: 14px;" ValidationGroup="addrsheet"&gt;                         &lt;/asp:CompareValidator&gt;
     &lt;/div&gt;
  </code></pre>