title: Why won't JS / JQuery read the text box values?
body: <p>I have looked all over for a reason behind why this code does not work and I am stumped. </p>
  
  <p>I have an ASPX page with C# code behind.  The HTML mark-up has a JQuery dialog that functions properly. When the submit button is clicked the dialog closes and the data is passed to a web exposed method and is written to the database.  All values are saved for the ddl and chkbox controls but the string value of the text box is empty.  The database is set to NOT NULL for the field the text box is populating and the data is being saved so I know data is being passed but it is not the value entered into the text box.</p>
  
  <p>The text box ID is txtCategoryName and the Client ID mode is set to static. I have tried to get the values using the following:</p>
  
  <pre><code>var CategoryName = $('#txtCategoryName').val();
  var CategoryName = $('#txtCategoryName').text();
  var CategoryName = $(document.getElementById('txtCategoryName')).text();
  var CategoryName = $(document.getElementById('txtCategoryName')).val();
  var CategoryName = document.getElementById('txtCategoryName').value;
  </code></pre>
  
  <p>All of these return the same blank field.  I tried them one at a time.
  Currently I am using this JS Code:</p>
  
  <pre><code>$(document).ready(function () {
  
  var CategoryDialog = $(".EditCategories");
  var BtnNew = $("#btnNew");
  var CatDDL = document.getElementById("ddlCategoryParent3");
  var CatChk = $("#chkCatActive").val();
  var CategoryID = 0;
  var CategoryName = $("#txtCategoryName").val();
  var ParentID = CatDDL.options[CatDDL.selectedIndex].value;
  if (CatChk) { CatChk = 1; } else { CatChk = 0; }
  
  
  
  var CatDialog = $(CategoryDialog.dialog({
  
      maxHeight: 1000,
      closeOnEscape: true,
      scrollable: false,
      width: 650,
      title: 'Category Editor',
      autoOpen: false,
  
  
      buttons: [
          {
              width: 170,
              text: "Save",
              icons: {
                  primary: "ui-icon-disk"
              },
              click: function () {
                  $(this).dialog("close");
                  window.alert(PageMethods.saveCat(CategoryName, ParentID, CategoryID, CatChk));
  
              }
  
          },
  
          {
              width: 170,
              text: "Delete",
              icons: {
                  primary: "ui-icon-circle-minus"
              },
              click: function () {
                  $(this).dialog("close");
              }
  
          },
          {
              width: 170,
              text: "Cancel",
              icons: {
                  primary: "ui-icon-circle-close"
              },
              click: function () {
                  $(this).dialog("close");
              }
  
          }
      ]
  })
  
  
  
  
  
  
  );
  
  
  
  BtnNew.click(function () {
      $(CatDialog).dialog('open');
      $(CatDialog).parent().appendTo($("form:first"));
  
  });
  
  
  
  
  });
  </code></pre>
  
  <p>The code markup for the aspx page (categories.aspx)</p>
  
  <pre><code>&lt;div class="EditCategories"&gt;
      &lt;div class="Table"&gt;
          &lt;div class="TableRow"&gt;
  
                  &lt;div class="TableCell"&gt;
                             &lt;div class="TextBlock220"&gt;Category Name &lt;/div&gt;
                  &lt;/div&gt;&lt;!-- End Table Cell --&gt;
                  &lt;div class="TableCell"&gt;
                      &lt;input id="txtCategoryName" class="ControlTextBox" /&gt;
                      &lt;!--&lt;asp:TextBox ID="txtCategoryName" CssClass="ControlTextBox" runat="server" ClientIDMode="Static"&gt;&lt;/asp:TextBox&gt;--&gt;
                   &lt;/div&gt;&lt;!--End Table Cell--&gt;
               &lt;/div&gt;&lt;!-- End Row 1 --&gt;
           &lt;div class="TableRow"&gt;
                 &lt;div class="TableCell"&gt;
                             Parent Category
                 &lt;/div&gt;&lt;!-- End Table Cell --&gt;
                 &lt;div class="TableCell"&gt;
                      &lt;asp:DropDownList ID="ddlCategoryParent3" runat="server" CssClass="ControlDropDownList" ClientIDMode="Static"&gt;&lt;/asp:DropDownList&gt;
                 &lt;/div&gt;&lt;!--End Table Cell--&gt;
           &lt;/div&gt;
           &lt;div class="TableRow"&gt;
                      &lt;div class="TableCell"&gt;
                            Active
                      &lt;/div&gt;&lt;!-- End Table Cell --&gt;
                      &lt;div class="TableCell"&gt;
                            &lt;asp:Checkbox ID="chkCatActive"      CssClass="ControlCheckBox" runat="server" ClientIDMode="Static"&gt;&lt;/asp:Checkbox&gt;
                      &lt;/div&gt;&lt;!--End Table Cell--&gt;
           &lt;/div&gt;&lt;!-- End Row 3--&gt;
  
  
          &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The C# Code behind method for the ASPX page:</p>
  
  <pre><code>[System.Web.Services.WebMethod()]
  [System.Web.Script.Services.ScriptMethod()]
  public static string saveCat(string _Name_, int _parent_id_, int ID, int _Status_)
  {
      Category eCT = new Category();
      eCT.CategoryName = _Name_;
      eCT.ParentID = _parent_id_;
      eCT.ID = ID;
      eCT.Status = _Status_;
      eCT.Save();
      return eCT.resultMessage; 
  }
  </code></pre>
  
  <p>And the save method:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// If the ID = 0 the data is written as a new category.
  /// If the ID is greater than 0 the data is updated.
  /// &lt;/summary&gt;
  /// &lt;returns&gt;The objects result value will hold the result of the attempt to update data as type Boolean.  The objects resultMessage value will contain the string result of the attempt to add data.&lt;/returns&gt;
  public void Save()
  {
  
      result = dl.CategoryExists(this);
      if (result) { resultMessage = "The parent category already contains a category named " + CategoryName.Trim(); }
      else { 
          if (ID &gt; 0)
          {
              if (!result) { resultMessage = "There was an unexpected error updating " + CategoryName.Trim() + ". No changes were saved."; }
          }
          else
          {
              result = dl.InsertCategory(this);
              if (!result) { resultMessage = "There was an unexpected error creating the Category."; }
          }
      }
      if (result) { resultMessage = "New Category Successfully Created"; }
  
  }
  </code></pre>
  
  <p>Any help is greatly appreciated thanks.</p>