當我在ASP.NET 4.5/Visual Studio 2012的Login.aspx
頁面啓動ASP.NET Web應用程序時,會出現用戶名和密碼文本框和登錄按鈕。ASP.NET 4.5 Web應用程序 - 用戶名/密碼文本框
當我雙擊按鈕(在VS)它創建代碼中的點擊事件。
當我嘗試使用用戶名/密碼箱是這樣的:
string username = Username.Text;
它說用戶名(文本框)不會在目前的情況下存在。
代碼Login.aspx.designer.cs
差不多空了。
namespace WebApplication2.Account
{
public partial class Login
{
/// <summary>
/// RegisterHyperLink control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.HyperLink RegisterHyperLink;
/// <summary>
/// OpenAuthLogin control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::WebApplication2.Account.OpenAuthProviders OpenAuthLogin;
}
}
Login.aspx
HTML
<%@ Page Title="Log in" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="WebApplication5.Account.Login" %>
<%@ Register Src="~/Account/OpenAuthProviders.ascx" TagPrefix="uc" TagName="OpenAuthProviders" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<hgroup class="title">
<h1><%: Title %>.</h1>
</hgroup>
<section id="loginForm">
<h2>Use a local account to log in.</h2>
<asp:Login 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 runat="server" AssociatedControlID="UserName">User name</asp:Label>
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="The user name field is required." />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="Password">Password</asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password" CssClass="field-validation-error" ErrorMessage="The password field is required." />
</li>
<li>
<asp:CheckBox runat="server" ID="RememberMe" />
<asp:Label runat="server" AssociatedControlID="RememberMe" CssClass="checkbox">Remember me?</asp:Label>
</li>
</ol>
<asp:Button runat="server" CommandName="Login" Text="Log in" />
</fieldset>
</LayoutTemplate>
</asp:Login>
<p>
<asp:HyperLink runat="server" ID="RegisterHyperLink" ViewStateMode="Disabled">Register</asp:HyperLink>
if you don't have an account.
</p>
</section>
<section id="socialLoginForm">
<h2>Use another service to log in.</h2>
<uc:OpenAuthProviders runat="server" ID="OpenAuthLogin" />
</section>
</asp:Content>
爲什麼這些控件是不是在designer.cs?
我失蹤了什麼?
謝謝,但我想重新開始新的項目,它再次爲空。試圖刪除設計師,並轉換,並再次相同。它不生成文本框的代碼。我更新了login.aspx的html代碼問題,也許這可以幫助... –
表單沒有被編輯過嗎?登錄表單沒有ID屬性: – Kurt
這是原始登錄表單。並且它是Visual Studio 2012. –