Click here to Skip to main content
15,899,627 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
ASP.NET
<%@ Page Title="Log In" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="EQ.Account.Login" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
    Log In
</h2>
<p>
    Please enter your Employee Code and password.
    If you don't have an account Please Contact your Manager.
</p>
<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false">
    <LayoutTemplate>
        <span class="failureNotification">
            <asp:Literal ID="FailureText" runat="server"></asp:Literal>
        </span>
        <asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification" 
             ValidationGroup="LoginUserValidationGroup"/>
        <div class="accountInfo">
            <fieldset class="login">
                <legend>Account Information</legend>
                <p>
                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>
                    <asp:TextBox ID="txtUserName" runat="server" CssClass="textEntry"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" 
                         CssClass="failureNotification" ErrorMessage="User Name is required." ToolTip="User Name is required." 
                         ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
                </p>
                <p>
                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                    <asp:TextBox ID="txtPassword" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" 
                         CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Password is required." 
                         ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
                </p>
                <p>
                    <asp:CheckBox ID="RememberMe" runat="server"/>
                    <asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" CssClass="inline">Keep me logged in</asp:Label>
                </p>
                <p>
                <asp:Label ID="lblErrorMessage" runat="server" CssClass="failureNotification" Visible="false" />
                </p>
            </fieldset>
            <p class="submitButton">
                <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="LoginUserValidationGroup" OnClick="LoginButton_Click"/>
            </p>
        </div>
    </LayoutTemplate>
</asp:Login>


This is my ASP page but in the CodeBehind page i.e. Login.aspx.cs, when i m trying to get the values of the controls like lblErrorMessage,txtuserName and txtPassword , i m getting error that "Error 1 The name 'txtUserName' does not exist in the current context C:\Users\dsingh\Documents\Visual Studio 2010\Projects\EQ\EQ\Account\Login.aspx.cs 64 46 EQ ". Waiting if some one will solve this problem and guide me that why it is not recognizing the controls from the code behind.
Posted
Comments
_Amy 29-Jun-12 3:10am    
Usually the Inherits attributes of @page directive is separated by "_" (Underscores). Try my answer below...
Dharmenrda Kumar Singh 29-Jun-12 3:42am    
Actually i m using Web Application instead of websites and i never developed any application on web application so don't know how to call the web controls in Web application.

1 solution

Hi,
I am not 100% sure but you just try replacing your @page directive with the code below:
ASP.NET
<%@ Page Title="Log In" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="EQ_Account_Login" %>

All the best.
--Amit
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900