无法从Codebehind调用Bootstrap页面上的控件

时间:2017-05-30 18:20:31

标签: asp.net vb.net bootstrap-4

由于某种原因,我无法从我的代码隐藏页面引用我的Bootstrap页面上的任何控件。作为一个例子,我尝试调用txtUsername控件,但在代码隐藏时它不识别控件。我尝试过重新创建页面,但仍然没有。txtUsername not recognised

我的网页

     <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="~/Access/login.aspx.vb" Inherits="Icon.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" >
<link rel="stylesheet" type="text/css" 
 ref="../StyleSheets/bootstrap/bootstrap.css">
        <link rel="stylesheet" type="text/css" href="../StyleSheets/template/login.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
        <link href='https://fonts.googleapis.com/css?family=Passion+One' rel='stylesheet' type='text/css'>
        <link href='https://fonts.googleapis.com/css?family=Oxygen' rel='stylesheet' type='text/css'>
        <title>Admin</title>
</head>
<body>
<div class="container">
    <div class="container">
            <div class="row main">
                <div class="panel-heading">
                   <div class="panel-title text-center">
                        <h2 class="title">Icon Enterprise</h1>
                        <hr />
                    </div>
                </div> 
                <div class="main-login main-center">
                    <form class="form-horizontal" method="post" action="#">

                        <div class="form-group">
                            <label for="txtUsername" id="lblUsername" class="cols-sm-2 control-label">Username</label>
                            <div class="cols-sm-10">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
                                    <input type="text" class="form-control" name="txtUsername" id="txtUsername"  placeholder="Your Username"/>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                        <label for="txtPassword" id="lblPassword" class="cols-sm-2 control-label">Password</label>
                            <div class="cols-sm-10">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-key fa" aria-hidden="true"></i></span>
                                    <input type="password" class="form-control" name="txtPassword" id="txtPassword"  placeholder="Your Password"/>
                                </div>
                                <div>
                                <label  id="lblError" style="color:Red">Incorrect Username or Password</label>
                                </div>
                            </div>
                        </div>

                        <div class="form-group ">
                            <button type="button" class="btn btn-primary btn-lg btn-block login-button">Submit</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <script type="text/javascript" src="../Scripts/bootstrap/bootstrap.js"></script>
</body>
</html>

我的Codebehind页面

Public Class login
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

结束班

2 个答案:

答案 0 :(得分:1)

那是因为txtUsername不是asp控件,服务器不知道它。

你想要的是:

<asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>

答案 1 :(得分:0)

您正在使用html输入控件,该控件在.cs文件中不可用,
为此,要么runat="server"放在你的控制之中
或使用asp.net文本框

 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>