Solved

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

Posted on 2011-03-18
5
589 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 33

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 50 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 450 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 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