Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,749 members, 7,817,071 topics. Date: Saturday, 04 May 2024 at 03:04 AM

How Do I Get A Value From Another Form Using C#.NET 2008 - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Do I Get A Value From Another Form Using C#.NET 2008 (2207 Views)

Plz Can Anyone Solve This Using C++? / I Need Help On Oop Project Using C# Console-base Application / An Introduction To Programming Using C (2) (3) (4)

(1) (Reply) (Go Down)

How Do I Get A Value From Another Form Using C#.NET 2008 by Lakulos(m): 4:35pm On Aug 31, 2012
Please i want to know how to get a value or values from a form and make it automatically appear on another form,i need the code format and explanation on how to do this,i googled it but i didn't understand how the code was used.Thanks.
Re: How Do I Get A Value From Another Form Using C#.NET 2008 by solomon201(m): 10:35am On Sep 01, 2012
I remember struggling with same problem for about 2 weeks when i was starting out newly. You can do it in two ways:constructor initialization and events. First and easiest you should have an overloaded constructor of the form you want to pass data to. Like public mynewform( string value) { // set and initialize your fields like textboxes and labels here.
Textbox1.text=value;
} then in your main form do something like this in the click event of the btn that creates and displays the new form:
string myname="john";
mynewform nameform=new mynewform(myname); nameform.show(); note this method works when the form is not yet created if you have the form already open along with other forms and want other forms to update another form automatically then you have to go through events. Let the parent or sending form have an event and then let the forms that need to be updated hook up to this event. With this way you can update multiple forms automatically at the same time. Sorry i'm using a phone i would have added very clear code samples.
Re: How Do I Get A Value From Another Form Using C#.NET 2008 by csharpjava(m): 12:56pm On Sep 01, 2012
@ Poster, what you need if you are working with asp.net is a Query String in .net, if you are still interested let me know and I will post a sample code here for you to see.
Re: How Do I Get A Value From Another Form Using C#.NET 2008 by lordstevens: 12:35am On Sep 02, 2012
if u have a textbox on d parent form say textbox1 and you want to transfer it to a child form having a label say label1! now on d form load event of the destination form type this code

Private Sub frmChild_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
label1.text= frmMain.textbox1.text
End Sub


now run the application type a value in the textbox and redirect it to the child form
u can also reach me at stephen.chidi@ymail.com for more tutorials
Re: How Do I Get A Value From Another Form Using C#.NET 2008 by csharpjava(m): 8:33pm On Sep 02, 2012
Here is an example if you are working with asp.net

Put this code within the body of the html page where the value will come from:

<asp:Label ID="Label1" runat="server" Text="Query String"></asp:Label>
<a href = "About.aspx?Answer=<%= Label1.Text %>"> Send to Another Page </a>

And this code below should go in the page load event of the server code of the .aspx page that will accept the value above

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Request.QueryString["Answer"];
}

(1) (Reply)

How To Make Money With Your Mobile Apps At Playjoor.com.ng / Any Interest In Lagos-based Code Camps? / Undergraduate Computer Project Topic

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.