473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to call the existing form in ASP.Net C# windows form?

Hi,

Thanks for help in advance!
In Form1, I "New" a Form2 and ShowDialog the Form2, it's OK.
My intention is passing a value from Form2 to Form1.
However, in Form2, I shouldn't "New" a Form1, 'cuz it will open a new Form1,
the new Form1 will get the value. And the original Form1 get nothing!
What do I need to do to let the ORIGINAL Form1 get the target value?
Any help will be highly appreciated.

Jason
Nov 17 '05 #1
4 1973
hello,
You can create a public static property and set it to any value and you can
access it in form1.
eg
public static string myvalue
{
set {value = "what ever"};
get {return value;}
}

"Jason Huang" <Ja************@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi,

Thanks for help in advance!
In Form1, I "New" a Form2 and ShowDialog the Form2, it's OK.
My intention is passing a value from Form2 to Form1.
However, in Form2, I shouldn't "New" a Form1, 'cuz it will open a new
Form1, the new Form1 will get the value. And the original Form1 get
nothing!
What do I need to do to let the ORIGINAL Form1 get the target value?
Any help will be highly appreciated.

Jason

Nov 17 '05 #2
Hi,

You have several ways to do so, like:

1- Pass a reference from form1 to form2, then when needed you can update
form1 , note that form1 should have a public member to receive the value
back
// in form 1
form2 = new Form2( this);
form2.ShowDialog();

//in form 2:
//constructor
public Form2( Form1 parent) { this.parentForm = parent;}

// in a method
parentForm.PublicProperty = "what ever value";
2- make tha value accesible to form1 as a public property:
// in form 1
form2 = new Form2( this);
form2.ShowDialog();
form1.receivedvalue = form2.PublicProperty;

3- Make a static public property in form1 , this is the last resort,

//form1
public static string A_Property { get.. set }

//form2
//inside a method:
//note I use the Form1 type, not any instnace
Form1.A_Property = "a value" ;
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jason Huang" <Ja************@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi,

Thanks for help in advance!
In Form1, I "New" a Form2 and ShowDialog the Form2, it's OK.
My intention is passing a value from Form2 to Form1.
However, in Form2, I shouldn't "New" a Form1, 'cuz it will open a new
Form1, the new Form1 will get the value. And the original Form1 get
nothing!
What do I need to do to let the ORIGINAL Form1 get the target value?
Any help will be highly appreciated.

Jason

Nov 17 '05 #3
Thank you for help me!
But I got another question for this.
Saying that Form3 and Form4 will be also using the Form2, then how do we
build up the Form2 constructor,
so that Form3 and Form4 can get the value passed from Form2? Given that
Form1, Form2, Form3 and Form4
have no mdi relationship.
Thanks in advance again.
Jason
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> ¼¶¼g©ó¶l¥ó·s»D:%2***************@tk2msftngp13.phx. gbl...
Hi,

You have several ways to do so, like:

1- Pass a reference from form1 to form2, then when needed you can update
form1 , note that form1 should have a public member to receive the value
back
// in form 1
form2 = new Form2( this);
form2.ShowDialog();

//in form 2:
//constructor
public Form2( Form1 parent) { this.parentForm = parent;}

// in a method
parentForm.PublicProperty = "what ever value";
2- make tha value accesible to form1 as a public property:
// in form 1
form2 = new Form2( this);
form2.ShowDialog();
form1.receivedvalue = form2.PublicProperty;

3- Make a static public property in form1 , this is the last resort,

//form1
public static string A_Property { get.. set }

//form2
//inside a method:
//note I use the Form1 type, not any instnace
Form1.A_Property = "a value" ;
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jason Huang" <Ja************@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi,

Thanks for help in advance!
In Form1, I "New" a Form2 and ShowDialog the Form2, it's OK.
My intention is passing a value from Form2 to Form1.
However, in Form2, I shouldn't "New" a Form1, 'cuz it will open a new
Form1, the new Form1 will get the value. And the original Form1 get
nothing!
What do I need to do to let the ORIGINAL Form1 get the target value?
Any help will be highly appreciated.

Jason


Nov 17 '05 #4
Hi Jason,
You kind of lost me, too many forms for so early in the morning :)

If your app is not MDI, and you know you will only have one instance of each
form created at the most, you can use a static property in each individual
form to hold a reference.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Jason Huang" <Ja************@hotmail.com> wrote in message
news:eK*************@tk2msftngp13.phx.gbl...
Thank you for help me!
But I got another question for this.
Saying that Form3 and Form4 will be also using the Form2, then how do we
build up the Form2 constructor,
so that Form3 and Form4 can get the value passed from Form2? Given that
Form1, Form2, Form3 and Form4
have no mdi relationship.
Thanks in advance again.
Jason
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
¼¶¼g©ó¶l¥ó·s»D:%2***************@tk2msftngp13.phx. gbl...
Hi,

You have several ways to do so, like:

1- Pass a reference from form1 to form2, then when needed you can update
form1 , note that form1 should have a public member to receive the value
back
// in form 1
form2 = new Form2( this);
form2.ShowDialog();

//in form 2:
//constructor
public Form2( Form1 parent) { this.parentForm = parent;}

// in a method
parentForm.PublicProperty = "what ever value";
2- make tha value accesible to form1 as a public property:
// in form 1
form2 = new Form2( this);
form2.ShowDialog();
form1.receivedvalue = form2.PublicProperty;

3- Make a static public property in form1 , this is the last resort,

//form1
public static string A_Property { get.. set }

//form2
//inside a method:
//note I use the Form1 type, not any instnace
Form1.A_Property = "a value" ;
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jason Huang" <Ja************@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi,

Thanks for help in advance!
In Form1, I "New" a Form2 and ShowDialog the Form2, it's OK.
My intention is passing a value from Form2 to Form1.
However, in Form2, I shouldn't "New" a Form1, 'cuz it will open a new
Form1, the new Form1 will get the value. And the original Form1 get
nothing!
What do I need to do to let the ORIGINAL Form1 get the target value?
Any help will be highly appreciated.

Jason



Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
1
by: Harmony407 | last post by:
Hello: Our organization uses MS Access to store all of our members information. Our primary database computer is running on Windows 98. This is where the main database exists. The MS Access...
3
by: David N | last post by:
Hi All, I just wonder if in C#, I can develop a user defined control that can call its parent function which is not yet developed. For example, how do I make my user control call a...
5
by: Anand Ganesh | last post by:
Hi All, I need some help. I am sort of not sure how to approach this problem. I have a MAINPROGRAM. This is the core application. I have asked two of my staff to developed two different...
2
by: PawelR | last post by:
Hello Group, In my application I have few class, and I want call function with "master class". This is as master form (startClass) and option window (ClassA). My question is how call function...
4
by: Paul | last post by:
Hi, I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
3
by: garyusenet | last post by:
Dear Professionals, I have recently been using the wonderful krypton toolkit and am trying to use them in my small hobby application. I include this bit of info as an aside really because i'm...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.