为什么每当我尝试调试我的代码时,我总是在 VS 中收到以下错误消息?
Error 2 The name 'Password' does not exist in the current context Login.aspx.cs 22 22 Team13
Error 1 The name 'UserName' does not exist in the current context Login.aspx.cs 21 27 Team13
这是我的 Login.aspx 代码
<form id="loginForm" runat="server">
<div id="login_box" runat="server">
<!-- LOGIN BOX -->
<asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate" Width="293px"
Height="172px">
<LayoutTemplate>
User Name:<br />
<asp:DropDownList ID="UserName" runat="server" DataSourceID="SqlDataSource1" DataTextField="dept"
DataValueField="id" Width="200px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:team13ConnectionString %>"
SelectCommand="SELECT [id],[dept] FROM [ts_dept] ORDER BY [id]"></asp:SqlDataSource>
<br /><br />
Password:<br />
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
<asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
<a href="http://89.200.143.163/~team13/login.php">Switch to PMW</a>
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1" />
</LayoutTemplate>
</asp:Login>
</div>
</form>
这是我的 Login.aspx.cs 代码
using System;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Configuration;
public partial class login : System.Web.UI.Page
{
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string username = Login1.UserName;
string pwd = Login1.Password;
string strConn;
strConn = WebConfigurationManager.ConnectionStrings["team13ConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();
string sqlUserName;
sqlUserName = "SELECT id,pass FROM ts_dept ";
sqlUserName += " WHERE (id ='" + username + "')";
sqlUserName += " AND (pass ='" + pwd + "')";
SqlCommand com = new SqlCommand(sqlUserName, Conn);
string CurrentName;
CurrentName = (string)com.ExecuteScalar();
if (CurrentName != null)
{
Session["UserAuthentication"] = username;
Session.Timeout = 1;
Response.Redirect("Default.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}