title: Login Page using ASP.Net & Ajax
body: <p>I'm trying to make a login page using html, ajax &amp; ASP.NET.The data is truly passed to the ajax function, but when I debug the asp page the username and password are sent with NULL.
  The code is supposed to take username &amp; password then returns the userid </p>
  
  <p>Html page:</p>
  
  <pre><code>    &lt;div id="usernameid"&gt;Username:&lt;/div&gt;&lt;input id="username" type="text"/&gt; &lt;span id="username_status"&gt;&lt;/span&gt;
      &lt;div id="passwordid"&gt;Password:&lt;/div&gt;&lt;input id="password" type="password"/&gt; &lt;span id="password_status"&gt;&lt;/span&gt;
      &lt;div&gt; &lt;input id="loginbutton" onclick="UserLogin()" type="submit" value="Submit" /&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>function UserLogin() {
  var postData = JSON.stringify({ "username": JSON.stringify($("#username").val()), "password": JSON.stringify($("#password").val()) });
  alert(postData);
  $.ajax({
      type: "GET",
  
      url: "http://localhost:49317/LoginPageForLearn.aspx",
      data: postData,
      contentType: "application/json; charset=utf-8",
      dataType: "jsonp",
      jsonp: 'jsoncallback',
      success: callbackfunction,
      error: function (msg) { alert(msg); }
      }); 
      }
      function callbackfunction(datacoming) {
      localStorage["UserID"] = datacoming;
      alert(datacoming);
  </code></pre>
  
  <p>Asp.net page: </p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
  
          string userName = "";
          int userId = -1;
          string PassWord = "";
          if (Request.QueryString.Count != 0 &amp;&amp; Request.QueryString["username"] != string.Empty &amp;&amp; Request.QueryString["password"] != string.Empty)
              {
                  userName = Request.QueryString["username"];
                  PassWord = Request.QueryString["password"];
                  userId = GetUserID(userName, PassWord);
  
              }
      }
  </code></pre>
  
  <p>Do you have any ideas why isn't the data passed correctly ? Or do you have any other ideas on how can I make a login page using html and access the data at SQL.</p>
  
  <p>Thanks a lot. </p>