title: Can't get a value out an ASP.NET hidden field
body: <p>I am going through a YouTube video, to learn ASP.NET.  I've gotten it to work for the most part, with a somewhat major caveat: I can't retrieve a value from a hidden field ID.  Because of that, I don't have a value to send to a stored procedure to create or update. </p>
  
  <p>The commented out line is the original statement. When I have that then execute 
  <code>.ExecuteNonQuery</code>, I get the following error: </p>
  
  <blockquote>
    <p>Procedure or function 'ResourceCreateOrUpdate' expects parameter '@ResourceID', which was not supplied</p>
  </blockquote>
  
  <p>When I try to display hfResourceID, I have nothing when trying to pass 0, for a create, or the ResourceID value, i.e. 1.  That value however, doesn't get there.  I know the stored procedure works because I can execute it in SQL Server Management.</p>
  
  <p>I tried moving hfResourceID to a string, then a integer value, but I seem to be having problems creating the if/else: everything is marked as an error.  When I hover over the lines, I get the following message, which pretty much leave me clueless: </p>
  
  <blockquote>
    <p>"Embedded statement cannot be a declaration or labeled statement".</p>
  </blockquote>
  
  <p>Would I be able to get any pointers on how to clear up my error, please?  Thanks.</p>
  
  <p><strong>2017-10-13 @ 10:38: code updated</strong></p>
  
  <pre><code>    &lt;asp:HiddenField ID="hfResourceID" runat="server" /&gt;
  
      protected void btnSave_Click(object sender, EventArgs e)
      {
          int intResourceID = 0;
          bool boolIDHasValue = true;
          try
          {
              intResourceID = Convert.ToInt32(hfResourceID.Value);
          }
          catch (Exception ex)
          {
              lblErrorMessage.Text = ex.Message;
              boolIDHasValue = false;
          }
          if (boolIDHasValue)
          {
              if (sqlconnODRConnection.State == System.Data.ConnectionState.Closed)
                  sqlconnODRConnection.Open();
              SqlCommand sqlcmdCreateOrUpdate = new SqlCommand("ResourceCreateOrUpdate", sqlconnODRConnection);
              sqlcmdCreateOrUpdate.Parameters.AddWithValue("@ResourceID", intResourceID);
              sqlcmdCreateOrUpdate.Parameters.AddWithValue("@Status", txtStatus.Text.Trim());
              sqlcmdCreateOrUpdate.Parameters.AddWithValue("@FirstName", txtFirstName.Text.Trim());
              sqlcmdCreateOrUpdate.Parameters.AddWithValue("@MiddleName", txtMiddleName.Text.Trim());
              sqlcmdCreateOrUpdate.Parameters.AddWithValue("@LastName", txtLastName.Text.Trim());
              sqlcmdCreateOrUpdate.Parameters.AddWithValue("@NickName", txtNickName.Text.Trim());
              sqlcmdCreateOrUpdate.Parameters.AddWithValue("@Gender", txtGender.Text.Trim());
              sqlcmdCreateOrUpdate.Parameters.AddWithValue("@USCitizen", txtUSCitizen.Text.Trim());
              sqlcmdCreateOrUpdate.ExecuteNonQuery();
              sqlconnODRConnection.Close();
              string strResourceID = hfResourceID.Value;
              Clear();
              if (strResourceID == "")
                  lblSuccessMessage.Text = "Saved Successfully";
              else
                  lblSuccessMessage.Text = "Updated Successfully";
              FillGridView();
          }
  
      }
  </code></pre>