title: How to compare database values with inputs through html form using c#
body: <p>Here's the template's HTML form :</p>
  
  <pre><code>&lt;form class="form-login" action="index.html"&gt;
              &lt;h2 class="form-login-heading"&gt;sign in now&lt;/h2&gt;
              &lt;div class="login-wrap"&gt;
                  &lt;input type="text" class="form-control" placeholder="User ID" autofocus="autofocus"&gt;
                  &lt;br&gt;
                  &lt;input type="password" class="form-control" placeholder="Password"&gt;
                  &lt;label class="checkbox"&gt;
                      &lt;span class="pull-right"&gt;
                          &lt;a data-toggle="modal" href="login.html#myModal"&gt; Forgot Password?&lt;/a&gt;
  
                      &lt;/span&gt;
                  &lt;/label&gt;
                  &lt;button class="btn btn-theme btn-block" href="index.html" type="submit"&gt;&lt;i class="fa fa-lock"&gt;&lt;/i&gt; SIGN IN&lt;/button&gt;
  </code></pre>
  
  <p>Here's my modification to it :</p>
  
  <pre><code>&lt;form id="form1" runat="server" class="form-login" method="post" action="HomeDoc.aspx"&gt;
          &lt;div&gt;
              &lt;h2 class="form-login-heading"&gt;sign in now&lt;/h2&gt;
                      &lt;div class="login-wrap"&gt;
                          &lt;input type="text" class="form-control" placeholder="User ID" id="userid" runat="server" autofocus="autofocus"/&gt;
                          &lt;br/&gt;
                          &lt;input type="password" class="form-control" placeholder="Password" id="password" runat="server" /&gt;
                          &lt;label class="checkbox"&gt;
                              &lt;span class="pull-right"&gt;
                                  &lt;a data-toggle="modal" href="StaffLogin.aspx#myModal"&gt; Forgot Password?&lt;/a&gt;
                              &lt;/span&gt;
                          &lt;/label&gt;
                          &lt;button class="btn btn-theme btn-block" runat="server" type="submit"&gt;&lt;i class="fa fa-lock"&gt;&lt;/i&gt; SIGN IN&lt;/button&gt;
  </code></pre>
  
  <p>Output: So far, the page i intend to redirect the user to is being loaded every time i click the submit button, irrespective of the userid/password.</p>
  
  <p>Question: What I want to do is compare the values of the 2 inputs here with the values in my SQLServer db using c#. </p>
  
  <p>Also, i know the c# code for setting up connection and comparing values with db for web forms. So, what specific changes to bring to that code for html form inputs?</p>
  
  <p>Please help. Thanks.</p>
  
  <p>EDIT: Sorry for not providing the back end code. Here(ignore any trivial syntax error):</p>
  
  <pre><code>public partial class StaffLogin : System.Web.UI.Page
  {
  protected void Page_Load(object sender, EventArgs e)
  {
  
  }
  protected void Login_Click(object sender, EventArgs e)
  {
      String getTextValuesUserID = Page.Request.Form["userid"].ToString();
      String getTextValuesPassword = Page.Request.Form["password"].ToString();
  
      //setting up connection with database 
      SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=C:\\Users\\Pavel\\Documents\\Visual Studio 2013\\WebSites\\IMS\\App_Data\\DatabaseIMS.mdf;Integrated Security=True");
      con.Open();
      SqlCommand cmd = new SqlCommand("select * from Doctor where userid=@userid and password=@password", con);
      cmd.Parameters.AddWithValue("@userid", getTextValuesUserID);
      cmd.Parameters.AddWithValue("@password", getTextValuesPassword);
      SqlDataAdapter da = new SqlDataAdapter(cmd);
      DataTable dt = new DataTable();
      da.Fill(dt);
      if (dt.Rows.Count &gt; 0)
      {
          //  Response.Redirect("UserLoggedIn.aspx");
          Response.Redirect("HomeDoc.aspx");
      }
      else
      {
          //javascript for invalid username and password Alert box
          ClientScript.RegisterStartupScript(Page.GetType(), "validation", "&lt;script language='javascript'&gt;alert('Invalid Username and password')&lt;/script&gt;");
      }
  }
  </code></pre>
  
  <p>}</p>