'The name does not exist in the current context'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MiziaQ
    New Member
    • Nov 2007
    • 63

    'The name does not exist in the current context'

    I'm trying to authenticate the user login in c#. I get the following 2 errors: 'the name 'login_username ' does not exist in the current context' and 'the name 'login_password ' does not exist in the current context'.

    index.aspx

    Code:
    <tr>
    			            <td>&nbsp;</td>
    			            <td>
    			                <asp:TextBox ID="login_username" runat="server" Width="160px"></asp:TextBox>
    			            </td>
                            <td>
                                <asp:TextBox ID="login_password" TextMode="password" runat="server" Width="160px"></asp:TextBox>
                            </td>
                            <td>
                                <asp:Button id="btnLogin" class ="btn" Text="Login" onClick="btnLogin_Authenticate" runat="server" Width="50px" />
    			            </td>
                        </tr>
    index.aspx.cs

    Code:
    protected void btnLogin_Authenticate(object sender, AuthenticateEventArgs e)
        {
    
            try
            {
    
                string username; //Get the email from the control
                string password; //Get the password from the control
    
                username = login_username.Text;
                password = login_password.Text;
    
                bool flag = AuthenticateUser(username, password);
    
                if (flag == true)
                {
    
                    e.Authenticated = true;
                    string randomString = Guid.NewGuid().ToString();
    
                    string url = "companyadmin.aspx?";
                    url += randomString;
                    Response.Redirect(url);
    
                }
                else
    
                    e.Authenticated = false;
                    Response.Redirect("~/loginattempt.aspx?retry");
            }
            catch (Exception)
            {
                e.Authenticated = false;
    
            }
        }
    Thanks in advance for the help!
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Do both of your files have matching names at the top of their contents?
    <%@ Page Language="C#" AutoEventWireup ="true" CodeFile="index .aspx.cs" Inherits="index " %>

    and

    public partial class index: System.Web.UI.P age

    Comment

    • MiziaQ
      New Member
      • Nov 2007
      • 63

      #3
      That got rid of the two errors - thanks! However, I now get a new error message.

      'No overload for 'btnLogin_Authe nticate' matches delegate 'System.EventHa ndler'. Any ideas?

      I appreciate it!

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Well I was wondering about that, I've never seen a button handler look like this:
        protected void btnLogin_Authen ticate(object sender, AuthenticateEve ntArgs e)


        I would think you would need to use:
        protected void btnLogin_Authen ticate(object sender, EventArgs e)

        That should match the expected handler for the button. I have no idea if e comes in as an instance of AuthenticateEve ntArgs, for me it is always a blank instance of EventArgs

        Comment

        Working...