473,545 Members | 2,802 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading values from another form

When you pull up a second form in your program,
how do you get the values from the form?

Form2 dataForm = new Form2();

dataForm.ShowDi alog();
if (dataForm.Dialo gResult == DialogResult.OK )
{
// I want to get the textBox1 data from the form
}
Thanks.
Mar 18 '08 #1
4 3938
In this case the best approach would be to expose what you want as public
properties on Form2 - i.e.

public string CustomerName {
get {return textBox1.Text;}
}

then you can access dataForm.Custom erName

For info, ShowDialog() [unlike Show()] doesn't Dispose() the form, so it
would be best to be "using" this - i.e.
using(Form2 dataForm = new Form2()) {
// do everything you want
}
// it is now disposed
Marc
Mar 18 '08 #2
Marc's solution most definitly works, I like to be a bit more complex
and make a private variable to hold the value and then a public
property to read the private variable. This way, when the user click
on OK on the second form, the second form can validate and make sure
everything is correct before loading the value into the variable and
exiting. If the user clicks on cancel, the value is never populated
and the first form, even if it tries to get the value, cannot.
Mar 18 '08 #3
Thanks Marc.

"Marc Gravell" <ma**********@g mail.comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
In this case the best approach would be to expose what you want as public
properties on Form2 - i.e.

Mar 18 '08 #4
Steve,

I use in those cases internal properties.

Cor

"Steve" <st******@ston. nischreef in bericht
news:em******** ******@TK2MSFTN GP06.phx.gbl...
When you pull up a second form in your program,
how do you get the values from the form?

Form2 dataForm = new Form2();

dataForm.ShowDi alog();
if (dataForm.Dialo gResult == DialogResult.OK )
{
// I want to get the textBox1 data from the form
}
Thanks.
Mar 18 '08 #5

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

Similar topics

6
12710
by: Suresh Kumaran | last post by:
Hi All, Does anybody know the sytax in VB.NET to write the contents of a multiline text box to a text file? Appreciate help. Suresh
1
6004
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that required fields in a form have values. I'm writing the values to the client using document.write only so that I can confirm that the values are there to...
12
4876
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same question twice! Here it is: I am having problems reading the value of a text Node. I think it has to do with the fact that the text is in a <span> tag....
5
2134
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.net / VB page with a Script (submitValues) and a Form. 1. The form has 20 input texts and a "Submit" button. 2. The script declares 20 variables. The value of each variable is taken from each of the 20 input texts. 3. When the button "Submit" is click the variable values are sent to an email address using AspNetEmail.
5
3715
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button. When the user clicks the "Add another email" it will call a client side JavaScript function, add_email, which will dynamically add a new set of...
3
1329
by: Peter Afonin | last post by:
Hello, I'm posting the data to another page and reading the results. I'm doing it approximately as described here: http://authors.aspalliance.com/stevesmith/articles/netscrape2.asp It works fine. But I'm getting the result as one string. I know the field names that are actually returned. Is there a way to return the value of each field...
23
1974
by: shank | last post by:
I have the below code found on an ASP site. <% arrName = Split(Request("TextArea"),",") %> <% For i = LBound(arrName) To UBound(arrName) Response.Write "ID: " & arrName(i) & "<br>" Next %>
6
1842
by: Sanjay | last post by:
Hi, Is it possible to save all the names/values of a form to another memo textfield before a Insert to the database then when required on another page split that memo textfield into the name and their corresponding values retrieved from the recordset ? Thanks, Sanj
5
5034
by: imailz | last post by:
Hi all, since I'm forced to switch from Fortran to C I wonder if there is posibility in C: 1) to use implicit loops 2) to parse several variables which number is determined at runtime. Following example: The output contains n columns which have to be read in. The number of
0
7943
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7456
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7786
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6022
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1919
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.