Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am basically new at Object Oriented programming

and I have a login page ----> WebLogin.aspx
and I have a class ----> Login.cs


for example I want to declare the following in my class:
C#
string username= txtUsername.Text.ToString();


how will I declare it to my Login.cs class.
Posted

Hey,

One of my friend had created an Article on the same, hope this will help you:

http://www.c-sharpcorner.com/UploadFile/2b481f/how-to-pass-data-from-one-form-to-another-form-using-class/[^]\

Accept the answer if it helps you
 
Share this answer
 
Well, it's a bad practice that what you're trying to achieve.
Instead, pass the control values as a parameters to the function of your class, which would return something.
For example,

Login.cs
C#
public string LogIn(string user, string password)
{
    string STATUS = string.empty;
    
    string query = "select * from User where UserName = '" + user + "', AND Password = '" + password + "'";
    SqlCommand cmd = new SqlCommand(query, con);
    
    int n = cmd.ExecuteNonQuery();
    
    STATUS = (n > 0 ? "Success !" : "Error");
    
    return STATUS;
}


WebLogin.aspx.cs
C#
{
    Login l = new Login();
    string status = l.LogIn(txtUserName.Text, txtPassword.Text);
    Response.Write(stauts);
}

It is just the basic idea, how you can go about this. Hope this would help you.

-KR
 
Share this answer
 
Comments
JB0301 25-Mar-14 0:54am    
Thankyou for this sir. I will be writing my code with the same concept. thanks
Create Read/Write property in the login class as

C#
public class Login
{
    public string UserName { get; set; }

    public void SomeMethod()
    {
        // read the username
        string username = this.UserName;
    }
}

and you can access the same(property) in the ASPX.cs by creating an instance to the Login class.

C#
public void button_click( object sender, EventArgs e)
   {
       Login login = new Login();
       login.UserName = "karthik";
       login.SomeMethod();
   }
 
Share this answer
 

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