Solved

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

Posted on 2011-03-18
5
550 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 32

Expert Comment

by:it_saige
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now