title: How to compare and check text box value with label value in event of text changed?
body: <p>I have a text box and label sitting next to each others. Label's text value comes from a drop down list. I have to turn the focus of text box to itself if, label's value is smaller than text box value and it goes on until, right value is entered in textbox.
  Can You help me?</p>
  
  <p>This is my code:-
  .aspx file:-</p>
  
  <pre><code>&lt;div class="row mb10"&gt;
     &lt;asp:Label runat="server" ID="lbl_Adults" CssClass="col-lg-2 control-label" Text="Adults : " AssociatedControlID="txt_Adults"&gt;&lt;/asp:Label&gt;
        &lt;div class="col-lg-6"&gt;
            &lt;div class="col-lg-4" style="margin-left:-15px;"&gt;
                &lt;asp:TextBox runat="server" ID="txt_Adults" CssClass="form-control" OnTextChanged="txt_Adults_TextChanged" AutoPostBack="true"&gt;&lt;/asp:TextBox&gt;
                &lt;asp:RequiredFieldValidator Font-Bold="true" ForeColor="Red" runat="server" ID="req_Adults" ControlToValidate="txt_Adults" ErrorMessage="Enter No. of Adults"&gt;&lt;/asp:RequiredFieldValidator&gt;
            &lt;/div&gt;
            &lt;div class="col-lg-8" style="font-family:'Copperplate Gothic'"&gt;
                  Only &lt;asp:Label runat="server" ID="lbl_No_Of_Adults"&gt;&lt;/asp:Label&gt; Adult(s) allowed.
            &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here's .cs file code:-</p>
  
  <pre><code>protected void txt_Adults_TextChanged(object sender, EventArgs e)
    {
  
       while (true)
       {
           if (txt_Adults==null)
           {
               txt_Adults.Text = Convert.ToString("0");
               txt_Adults.Focus();
               //txt_Adults_TextChanged(sender, e);
           }
           else if (Convert.ToInt32(txt_Adults.Text) &gt; Max_NoAdults)
           {
               txt_Adults.Text = Convert.ToString("0");
               txt_Adults.Focus();
               //txt_Adults_TextChanged(sender, e);
  
           }
           else
           {
               NoAdults = Convert.ToInt32(txt_Adults.Text);
               //NoAdults is a static variable that collects final(right) value of txt_Adults.text;
               break;
           }
  
       }
  
   }
  </code></pre>