我點擊了20個試圖在不同網站上解決這個問題的鏈接。ASP.net名稱'userName'在當前上下文中不存在
請幫我
所以我想做一個簡單的登錄身份驗證。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
public partial class Account_Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void loginButton_Click(object sender, EventArgs e)
{
if(FormsAuthentication.Authenticate(UserName.Text, Password.Text)
{
}
}
}
但錯誤消息彈出說「這個名字‘用戶名’不會在目前情況下存在」和名字‘密碼’不在當前情況下存在。
這裏是ASPX代碼
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Account_Login" %>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<hgroup class="title">
<h1>Login Page</h1>
</hgroup>
<section id="loginForm">
<asp:Login ID="Login1" runat="server" ViewStateMode="Disabled" RenderOuterTable="false">
<LayoutTemplate>
<p class="validation-summary-errors">
<asp:Literal runat="server" ID="FailureText" />
</p>
<fieldset>
<legend>Log in Form</legend>
<ol>
<li>
<asp:Label ID="Label1" runat="server" AssociatedControlID="UserName">User name</asp:Label>
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="The user name field is required." />
</li>
<li>
<asp:Label ID="Label2" runat="server" AssociatedControlID="Password">Password</asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Password" CssClass="field-validation-error" ErrorMessage="The password field is required." />
</li>
<li>
<asp:CheckBox runat="server" ID="RememberMe" />
<asp:Label ID="Label3" runat="server" AssociatedControlID="RememberMe" CssClass="checkbox">Remember me?</asp:Label>
</li>
</ol>
<asp:Button ID="loginButton" runat="server" CommandName="Login" Text="Log in" OnClick="loginButton_Click" />
</fieldset>
</LayoutTemplate>
</asp:Login>
<p>
<a href="Register.aspx">Register</a>
if you don't have an account.
</p>
</section>
請幫我:)
該ID用戶名不是用戶名... – 2014-09-04 12:54:54
哎呀,對不起,我是測試如果駱駝套管影響它。但它並沒有忘記改變價值。 但我仍然得到相同的錯誤,謝謝:) – helloGoodDay 2014-09-04 22:23:00