Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
how to pass value as form of object from class file to aspx.cs file

exe:-
C#
//it is my test.cs
 name = sagar;
 age = 23;
 id= 1234;

obj.value(name,age,id);// name, age and id should be in single object 


// it is my testing.aspx.cs
   in aspx i call the test.cs file 
    
 if i write,
 string UNAME =obj.name; // so i want in string sagar


Please let me know is this possible?

If yes then please tell me how or any logic to solve this problem?
Posted
Updated 6-Feb-12 1:30am
v3
Comments
Anuja Pawar Indore 6-Feb-12 7:31am    
Grammar and tag corrected

obj.value(name,age,id);// name, age and id should be in single object

This statement ... which only makes sense in the totally weird case that 'value is a method defined in an instance of a Class named 'obj ... which happens to be available in the context this code is defined in ...

Indicates to me that right now you are very confused about what Objects/Classes, and Methods, are, and you are not familiar with .NET naming conventions at all.

I suggest what you need to do is to get a good basic book on C#, or ASP.NET, and focus on understanding what a Class/Object is, what Methods are, how Methods are called using the "." suffix after the Class name, when they cannot be called directly in a code context.

And, learn to name Classes descriptively, by indicating what they "are;" learn to name Methods in a way that indicate what they "do."

One example of how this code might "make sense" is:
public class Person
{
   public string Name { get; set; }
   public int ID { get; set; }
   public int Age { get; set; }

   // the constructor for the Class
   public Person(string name, int id, int age)
   {
      Name = name;
      ID = id;
      Age = age;
   }
}
You create a new instance of the Class "Person," like this:
Person newPerson = new Person("sagar", 1234, 23);
At which point you can access any property of the "newPerson" instance of the Class named 'Person" like so:
string UserName = newPerson.Name;
Some hard work now, to get the fundamentals down, will reward you greatly in the future.

good luck !
 
Share this answer
 
You have to make variables public so that you can use them in aspx.cs

C#
public name="sagar";


or if you dont want to make them public, you can make public properties in Test.cs

C#
public Name{
get{
return name;
}
set{
name=value;
}
}


and now you can use this property in your aspx.cs file
C#
string uname=obj.Name;
 
Share this answer
 
v2
Comments
maddysagar 6-Feb-12 4:54am    
sir but how to make object and where it declare to get values in form of object from .cs to aspx.cs?
Syed Salman Raza Zaidi 6-Feb-12 6:34am    
1st: Make your testclass Public( ie use public modifier like public class Test)

2nd: in your aspx.cs file make object on page load event like Test obj=new Test();

3rd: call Test Properties like obj.Name;

Make sure your Test.cs file is located in App_Code folder

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