?
Solved

passing variables from a class in app_code without using 'return' - asp.net c#

Posted on 2011-03-18
5
Medium Priority
?
622 Views
Last Modified: 2012-05-11
Hi,

How can i pass a variable such as a string or a no. from the class file to a webform control or the webforms codebehind file?

Can i use a session variable?

i cant use:

return variablehere;

as its used for another purpose already.. I hope this makes sense.

Thanks,

Sam
0
Comment
Question by:OTM
5 Comments
 
LVL 35

Expert Comment

by:it_saige
ID: 35167481
You could pass the variable as a method parameter by reference and set the variable inside the function.

http://msdn.microsoft.com/en-us/library/0f66670z(v=vs.71).aspx

-saige-
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35167515
You could use a Session variable, but it is a bit of a messy solution. Your other options are either a "ref" variable, or an "out" variable:

    http://www.c-sharpcorner.com/UploadFile/mahesh/out_and_ref11112005002102AM/out_and_ref.aspx
0
 
LVL 10

Assisted Solution

by:ALaRiva
ALaRiva earned 200 total points
ID: 35167794
Would it not be easier to just use a getter instead of going the session route?
0
 
LVL 4

Accepted Solution

by:
abhinayp earned 1800 total points
ID: 35168222
Properties are best for u..

Here is a sample
//Ur classfile in AppCode

Public Class EmpClass
{
    private string _strFirstname;
    private string _strLastname;
   public string Firstname {
	get { return _strFirstname; }
	set { _strFirstname = value; }
   }
   public string Lastname {
	get { return _strLastname; }
	set { _strLastname = value; }
    }
public void EmployeeGet(int empID)
{
   _strLastname=GetEmployeLastName(empID);//ur code to get first name
   _strFirstname = GetEmployeeFirstName(empID); //ur code to get last name
}
}

// in ur webforms codebehind
 
EmpClass emp = new EmpClass();
emp.EmployeeGet(id);
lblFirstName.Text = emp.FirstName;
lblLastName.Text = emp.LastName;

Open in new window

0
 

Author Closing Comment

by:OTM
ID: 35169443
A "getter" was exactly what i needed, i just needed a good example to learn from and now i've implemented this into my project.

Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question