无法使用 html 文本框登录

2024-02-17

因为我使用html按钮和文本框来登录,所以我必须在源代码中的javascript中执行后面的代码才能执行后面的代码。无论我使用正确的用户名和密码(Admin 和 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)
    {

    }


}

You are 不使用asp.net服务器控件访问类似的值

txtUserName.Value

相反,您正在使用Javascript on HTML控制。所以,你的语法应该是这样的:

if (document.getElementById("txtUserName").value == "Admin" && document.getElementById("txtPassword").value == "123")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 html 文本框登录 的相关文章

随机推荐