c# – 无法使用html文本框登录
发布时间:2020-12-16 00:24:03 所属栏目:百科 来源:网络整理
导读:因为我使用html按钮和文本框登录,我必须在源代码中的 javascript中执行代码,以便执行后面的代码.无论我使用管理员和123的正确用户名和密码登录并单击登录按钮,或者我没有输入任何内容并单击登录按钮,它总是将我重定向到ResultDetails.aspx.这意味着登录失败.
因为我使用html按钮和文本框登录,我必须在源代码中的
javascript中执行代码,以便执行后面的代码.无论我使用管理员和123的正确用户名和密码登录并单击登录按钮,或者我没有输入任何内容并单击登录按钮,它总是将我重定向到ResultDetails.aspx.这意味着登录失败.如果它将我重定向到Search.aspx,则会通过登录.怎么了?即使我将.Value更改为.Text,它仍然是相同的效果
我的源代码 <%@ 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 as Hardcoded User //Do your 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 the form below to login to my 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> 我的代码背后的代码 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) { } } 解决方法
您可以尝试下面的代码,使用JavaScript中的id从文本框中获取值.
function Button1_onclick() { if (document.getElementById('txtUserName').value == "Admin" && document.getElementById('txtPassword').value == "123") { //Login as Hardcoded User //Do your stuff window.location.assign("Search.aspx") } else { window.location.assign("ResultDetails.aspx") } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |