title: Enable/disable button based on text input in Blazor Server Side
body: <p>I have a simple Blazor Server app and would like to enable a button when there is text in an input, and disable the button if there is no text in the input.  I have looked at and tried numerous examples, and have not come up with a working solution yet. This is for a page with a search button, which requires valid text before the search button becomes enabled.</p>
  
  <p>So, when as a user enters a character in the text input, button is enable.  If the user deletes all the text in the input, button is disabled. </p>
  
  <p>Here is the simplified code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@page "/InputExample"
  
  &lt;h3&gt;Input Example&lt;/h3&gt;
  
  &lt;input type="text" @onkeyup="@(e =&gt; EnableButton(e))" @bind="myInputText" /&gt;
  
  @if (disableState == true)
  {
      &lt;input type="button" value="I'm disabled" disabled="@buttonState"&gt;
  }
  else
  {
      &lt;input type="button" value="I'm not disabled"&gt;
  }
  
  @code 
  {
      private string buttonState = "disabled";
      private string myInputText = "";
      bool disableState = true;
  
      public void EnableButton(EventArgs args)
      {
          if (myInputText.Length == 0)
          {
              disableState = true;
          }
          else
          {
              disableState = false;
          }
      }
  
  }</code></pre>
  </div>
  </div>
  </p>