可以';使用HTML文本框登录将不起作用 [英] Can';t work using html textbox to login

查看:167
本文介绍了可以';使用HTML文本框登录将不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我使用的HTML按钮和文本框进行登录,我必须做的code后面在源$ C ​​$ c中的JavaScript才能做code后面。无论我登录使用正确的用户名和密码是Admin和123,点击登录按钮,或者我什么类型,然后点击登录按钮,它总是重定向我ResultDetails.aspx。这意味着登录失败。如果它重定向我Search.aspx登录会通过。怎么了?即使我更改为.value的。文本,它仍然是同样的效果。

我的SOURCE code

 <%@页面语言=C#AutoEventWireup =真codeFILE =Login.aspx.cs继承=登录%GT;!< D​​OCTYPE HTML PUBLIC -  // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
<头=服务器>
    <标题>< /标题>
    <风格类型=文/ CSS>    < /风格>
    <链接rel =stylesheet属性类型=文/ CSS的href =样式表/ loginstyle.css/>
    < SCRIPT LANGUAGE =JavaScript的类型=文/ JavaScript的>
//<![CDATA [
        功能Button1_onclick(){            如果(txtUserName.Value ==管理和放大器;&安培; txtPassword.Value ==123){
                //登录硬codeD用户                //做你的东西
                window.location.assign(Search.aspx)
            }
            其他{
                window.location.assign(ResultDetails.aspx)
            }
        }//]]>
    < / SCRIPT>
< /头>
<身体GT;< D​​IV ID =包装>    <表格名称=登录形式级=登录形式的行动=方法=后>        < D​​IV CLASS =头>
        < H1>登录表单< / H1>
        <跨度>填写下面的表单登录到我的超级真棒虚控制面板与LT; / SPAN>
        < / DIV>        < D​​IV CLASS =内容>
        <输入名称=用户名类型=文本级=输入用户名占位符=用户名=服务器ID =txtUserName/>
        < D​​IV CLASS =用户图标>< / DIV>
        <输入名称=密码TYPE =密码级=输入密码占位符=密码=服务器ID =txtPassword/>
        < D​​IV CLASS =传递图标>< / DIV>
        < / DIV>        < D​​IV CLASS =页脚>
        <输入类型=按钮NAME =提交值=登录级=按钮=服务器ID =Button1的önserverclick=的button1_Click的onclick =返回Button1_onclick()/>
        < / DIV>    < /表及GT;< / DIV>
< D​​IV CLASS =梯度>< / DIV>
< /身体GT;
< / HTML>

我的code背后code

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;公共部分类登录:System.Web.UI.Page
{
    保护无效的Page_Load(对象发件人,EventArgs的发送)
    {    }
}


解决方案

您可以试试下面code这提取使用id在JavaScript中,从文本框的值。

 函数Button1_onclick(){            如果(的document.getElementById('txtUserName')值==管理和放大器;&放大器;的document.getElementById('txtPassword')值==123。){
                //登录硬codeD用户                //做你的东西
                window.location.assign(Search.aspx)
            }
            其他{
                window.location.assign(ResultDetails.aspx)
            }
        }

Because I am using html buttons and textbox to login, I must do the code behind in the javascript in the source code in order to do the code behind. Whether I login using the correct username and password which is Admin and 123 and click the login button, or I type in nothing and click the login button, it always redirects me to ResultDetails.aspx. That means login fail. Login will pass if it redirect me to Search.aspx. What's Wrong? Even if I change .Value to .Text, it is still the same effect

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 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>

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 which fetches the value from text boxes using the id in JavaScript.

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")
            }           
        }

这篇关于可以';使用HTML文本框登录将不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆