c# - Can';t work using html textbox to login -


because using html buttons , textbox login, must code behind in javascript in source code in order code behind. whether login using correct username , password admin , 123 , click login button, or type in nothing , click login button, redirects me resultdetails.aspx. means login fail. login pass if redirect me search.aspx. what's wrong? if change .value .text, still same effect

enter image description here

my source code

<%@ page language="c#" autoeventwireup="true" codefile="login.aspx.cs" inherits="login" %>  <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title>     <style type="text/css">      </style>     <link rel="stylesheet" type="text/css" href="stylesheets/loginstyle.css" />     <script language="javascript" type="text/javascript"> // <![cdata[             function button1_onclick() {              if (txtusername.value == "admin" && txtpassword.value == "123") {                 //login hardcoded user                  //do stuff                 window.location.assign("search.aspx")               }             else {                 window.location.assign("resultdetails.aspx")             }                    }  // ]]>     </script> </head> <body>  <div id="wrapper">      <form name="login-form" class="login-form" action="" method="post">          <div class="header">         <h1>login form</h1>         <span>fill out form below login super awesome imaginary control panel.</span>         </div>          <div class="content">         <input name="username" type="text" class="input username" placeholder="username" runat="server" id="txtusername" />         <div class="user-icon"></div>         <input name="password" type="password" class="input password" placeholder="password" runat="server" id="txtpassword" />         <div class="pass-icon"></div>                </div>          <div class="footer">         <input type="button" name="submit" value="login" class="button" runat="server" id="button1" önserverclick="button1_click"  onclick="return button1_onclick()" />         </div>      </form>  </div> <div class="gradient"></div> </body> </html> 

my code behind code

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols;  public partial class login : system.web.ui.page {     protected void page_load(object sender, eventargs e)     {      }   } 

you can try below code fetches value text boxes using id in javascript.

function button1_onclick() {              if (document.getelementbyid('txtusername').value == "admin" && document.getelementbyid('txtpassword').value == "123") {                 //login hardcoded user                  //do stuff                 window.location.assign("search.aspx")               }             else {                 window.location.assign("resultdetails.aspx")             }                    } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -