Solved

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

Posted on 2011-03-18
5
594 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 34

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Form Data Disappears Using Back Button 4 66
Multi-Column Repeater 3 39
history of pages 7 52
Issue in displaying table columns on selection of dropdown 2 27
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

732 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