Solved

Passing values

Posted on 2012-03-24
4
249 Views
Last Modified: 2012-03-25
Hi,

How can pass value from a Form to a Class in c# 2010?

Please help.

Thanks
0
Comment
Question by:ayha1999
[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
  • 2
4 Comments
 
LVL 10

Assisted Solution

by:himanshut
himanshut earned 250 total points
ID: 37762282
You can use Sessions to store values that you have to pass and then pass those Session Values to method that can be used by creating instance of the Class( so that all the methods of that class can be accessed).
0
 
LVL 10

Accepted Solution

by:
Umar Topia earned 250 total points
ID: 37762293
You can create a method in class which you can call with parameters like:

MyClass mc = new MyClass();
mc.CustomMethod(sFirtstName,sLastName);

or else you can create the parameterised Constructor

MyClass mc = new MyClass(sFirstName,sLastName);
0
 
LVL 7

Author Comment

by:ayha1999
ID: 37762456
here I am trying access value from Form2 class into dbo2 class but ended up with error. how can I access txtRef in the dbo2 class?

the error

Error      1      The name 'txtRef' does not exist in the current context      

namespace myProject
{
   public partial class Form2: Form
   {
       public Form2 ( )
       {
          InitializeComponent ();
       }

       private void Form2_Load (object sender, EventArgs e)
       {

       }
       }

       private string txtRef=string.Empty;

       public string _Ref
       {
          set { txtRef=value; }
       }
   }

   public class dob2: DataSet
   {
       private DataTable dt2;
       string str = txtRef;   <--- values to be accepted here.

       public dob2 ( )
       {
      }
}

}

thanks
0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 37762879
Thanks
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Save json data from URL using SSIS 1 76
Convert VB web project to C# 3 66
Using sample Autorize.net c# simple example 1 53
Run software updates from the website 6 50
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

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