i just wanted to know how we can access the variable of 1 form to another form.as far as i know, ther is no session management concept in C#.

for ex., i want to access my login id into the next form. then what will be the procedure to do so?

thnks for the help..

Recommended Answers

If you did a search here, you would probably have found this snippet : http://www.daniweb.com/code/snippet1008.html

Jump to Post

Or, create a constructor in Form2 which take loginId String as parameter.

Jump to Post

All 8 Replies

it is simple.... all you need to do is to create a private variable in you 2nd from then assign a public interface in the following way

private string a;// create a property
public string IntefaceForA
return a;
a = value;

then in the form from where you need to pass values
you need to assign the value to that variable.

form2 obj = new form2();
obj.InterFaceForA = "loginID";


now you can access the value any where in your 2nd form;

I hope this solves your problem..

Or how to pass it when making/opening the other form

obj.show() will show/open the other form.... so you have to assigne that before doing this as i have shown previously

Or, override the show function with a variable to make it so you pass the required variables with it.

Or simply post the variables in the constructor.
// Jerry

Or, create a constructor in Form2 which take loginId String as parameter.

thanks! it really helped :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.