locked
cannot access non-static member of outer type error RRS feed

  • Question

  • I get a 'cannot access non-static member of outer type error 'ASP.login.aspx' via nested 'ASP.login_aspx.login' error.  I'm not sure what to do, how to fix.

    Here is my code, I get the error in the C# code where it says Login1.

    <%@ Import Namespace="System.Data" %> 
    <%@ Import Namespace="System.Configuration" %> 
    <%@ Import Namespace="System.Collections" %> 
    <%@ Import Namespace="System.Web" %> 
    <%@ Import Namespace="System.Web.Security" %> 
    <%@ Import Namespace="System.Web.UI" %> 
    <%@ Import Namespace="System.Web.UI.WebControls" %> 
    <%@ Import Namespace="System.Web.UI.WebControls.WebParts" %> 
    <%@ Import Namespace="System.Web.UI.HtmlControls" %> 
    <%@ Import Namespace="System.Data.SqlClients" %> 
    <%@ Import Namespace="Weaver" %> 
    <%@ Page Language="C#" %> 
     
     
     
    <script runat="server"> 
    //using System.Data; 
    //using System.Configuration; 
    //using System.Collections; 
    //using System.Web; 
    //using System.Web.Security; 
    //using System.Web.UI; 
    //using System.Web.UI.WebControls; 
    //using System.Web.UI.WebControls.WebParts; 
    //using System.Web.UI.HtmlControls; 
    //using System.Data.SqlClient; 
     
     
        public partial class login : System.Web.UI.Page 
        { 
            protected void Page_Load(object sender, System.EventArgs e) 
            { 
     
     
     
            } 
     
     
            private bool AuthenticateUser(string uname, string password, out int userID) 
            { 
                
                bool bflag = false; 
               
                //ConfigurationManager.ConnectionStrings("DBConnectionString"); 
                string queryString = "Data Source = test; Initial Catalog = test; User Id = webservices; Password = TEST"; 
                 
                string strSQL = "select * from icc_users where username ='" + uname + "' AND password ='" + password + "'"; 
               // Response.Write(strSQL); 
               // strSQL.Replace("[USERNAME]", uname); 
                //strSQL.Replace("[PASSWORD]", password); 
     
                userID = -1; 
                using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(queryString)) 
                { 
                    System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(strSQL, connection); 
                    connection.Open(); 
     
                    System.Data.SqlClient.SqlDataReader reader = command.ExecuteReader(); 
     
                    { 
                        // Call Read before accessing data. 
                        if (reader.Read()) 
                        { 
                            userID = System.Convert.ToInt32(reader[0]); 
                            bflag = true; 
                        } 
     
                        // Call Close when done reading. 
                        reader.Close(); 
     
                    } 
     
                    return bflag; 
     
                } 
            } 
     
            protected void Login1_Authenticate1(object sender, AuthenticateEventArgs e) 
            { 
     
                try 
                { 
     
                    string uname = Login1.UserName.Trim(); //Get the username from the control 
     
                    string password = Login1.Password.Trim(); //get the Password from the control 
                    //changed 
                     
     
                    int userID; 
                    bool flag = AuthenticateUser(uname, password, out userID); 
     
                    if (flag == true) 
                    { 
     
                        e.Authenticated = true; 
                        //Changed 
                        HttpContext.Current.Session["userID"] = userID; 
                        if (password.Length > 4) 
                        { 
                            password = password.Remove(0, password.Length - 4); 
                        } 
                        HttpContext.Current.Session["password"] = password; 
                        Login1.DestinationPageUrl = "reports.aspx"; 
     
     
                    } 
     
                    else 
     
                        e.Authenticated = false; 
     
                } 
     
                catch (System.Exception) 
                { 
     
                    e.Authenticated = false; 
     
                } 
     
            } 
     
            private bool AuthenticateUser(string uname, string password) 
            { 
                throw new System.Exception("The method or operation is not implemented."); 
            } 
        } 
    } 
     
    </script> 
     
     
     
    <form id="Form1" runat="server"> 
    <div class="content"> 
        
                    <h2>LOGIN: <span></span></h2> 
     
     
    <p>Welcome to online claims and customer service applications for International clients.  Once you log in, you can view the status of your claims and cases, get customer reports, send messages to HSI staff via a secure e-channel, and much more.  If you do not have a user name and password, please email us at <a href="mailto:support@us-hsi.com">support@us-hsi.com</a> </p> 
     
    <h4 id="1" style="text-align: center"> 
        <br /> 
        &nbsp; 
        <asp:Login ID="Login1" runat="server" BackColor="#F7F7DE" BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt" OnAuthenticate="Login1_Authenticate1"> 
            <TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" /> 
             
        </asp:Login> 
        &nbsp; 
         
        <br /> 
        <br /> 
        </h4> 
      <ul id="loginUL" runat="server"> 
             
    </ul> 
     
    </div> 
    </form> 
     
    

    • Moved by Bob Shen Friday, May 18, 2012 3:10 AM (From:Visual C# General)
    Thursday, May 17, 2012 4:44 PM

All replies

  • Looks like you mix different styles of ASP pages. If you want to use ‘<script runat="server">’, then do not define the class login, i.e. remove ‘public partial class login : System.Web.UI.Page  {‘ and unneeded ‘}’. 

    Thursday, May 17, 2012 7:31 PM
  • Hi bootzilla,

    You are more likely to get more efficient responses to ASP.NET issues at http://forums.asp.net where you can contact ASP.NET experts.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Mr. Wharty Thursday, May 31, 2012 2:49 AM
    Friday, May 18, 2012 3:10 AM