Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made 2 forms. and i have inserted 6,6 text boxes in each form . an i want to display all the information of the previous two forms in the next form . plz somebody tell me the correct syntax to display the information of the last two forms in the next from.
Posted
Comments
BillWoodruff 13-Nov-11 19:27pm    
Please tag your question so we can know if it's WinForms, or WPF, or ... ?

Are you saying you are going to create a third form, and in that third form you want to display all the text in the textboxes in the first two forms ?

If that's the case, then how, on the third form, do you wish to display the text: in a bunch of textboxes ? or ... ?

 
Share this answer
 
Comments
zahra1991 12-Nov-11 3:57am    
but how?? what is the syntax for that?
Sander Rossel 12-Nov-11 4:26am    
Good answer, my 5.
Assuming you are using WinForms, rather than a web based solution, the easiest way is to either:
1) Create a couple of public properties in the destination form and set them just before you call the Show or ShowDialog methods.
or
2) Create a constructor for the destination form which takes the necessary parameters for display.

Either way you encapsulate the data and only feed the destination form instance the data it requires.
 
Share this answer
 
Comments
Sander Rossel 12-Nov-11 4:25am    
That's correct, my 5. I answered the same question a while back. Copied the entire answer I gave back then, which has some code examples of the methods you mention here.
Use the Properties of Get{ } and Set { } Method.
 
Share this answer
 
Copied this answer from a previous answer I gave to the same question.
Here is the original question. There are more good answers to be found there: How to pass the Value one form to another form in windows form[^]

There are different ways to do this.
One is using a Property on one of your Forms.
C#
MyForm frm = new MyForm();
// It is possible to set MyValue at any point in your code, as long as you have a reference to an instance of MyForm.
frm.MyValue = "some value";
frm.Show();

Another is passing it to the constructor.
C#
public partial class MyForm : Form
{
   private String _myValue;
   public Form1(String myValue)
   {
      InitializeComponent();
      _myValue = myValue;
      // Possibly use myValue here.
   }
   // Do stuff with _myValue here.
}
Usage would look like this:
C#
MyForm frm = new MyForm("some value");
frm.Show();

Another approach could be to use a Method...
C#
public partial class MyForm : Form
{
   private String _myValue;
   public void SetValue(String myValue)
   {
      _myValue = myValue;
     // Possibly do stuff with myValue here.
   }
   // Or use _myValue here.
}
Usage:
C#
MyForm frm = new MyForm();
frm.Show();
// Once again, you can use this anywhere in your code, as long as you have a reference to the instance of MyForm.
frm.SetValue("some value");
Hope it helps! :)
 
Share this answer
 
This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

—SA
 
Share this answer
 
Hi zahra1991,

In the first aspx page set the PostBackUrl of the submit button to the next web form :


ASP.NET
<form id="form1" runat="server">
 <div>
 <asp:textbox id="name" runat="server" xmlns:asp="#unknown"></asp:textbox>
 <asp:button id="Button1" runat="server" text="Next" postbackurl="tester.aspx" xmlns:asp="#unknown" />
 </div>
 </form>


and in the second form you have the name value in the Params of Request

C#
protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("name = " + Request.Params["name"].ToString());
}


Please mark it as an answer or vote it up if it helped you.
Thanks.
 
Share this answer
 
GDC (Global Data Container) is the solution to store the data across various pages. You can implement your own way of GDC as global variables, etc.
 
Share this answer
 
Comments
zahra1991 12-Nov-11 3:49am    
but i dont know its syntax , as i am a beginner in C#. would you please help me out ?
OriginalGriff 12-Nov-11 3:59am    
Reason for my vote of one:
That is a bad idea. C# does not have a concept of Global Data - the only way to emulate this is to use static variables which means that a single instance of the variable is available to all instances within the application. This is against the principles of OOP, as well as being a maintenance headache when you expand the application at a future date.
Sander Rossel 12-Nov-11 4:20am    
I couldn't agree more!
store textbox value in session or static variable then using session or static variable insert into textbox of secon web form

try it
session["abc"]=textbox1.text;

on next page

textbox1.text=session["abc"].tostring();
 
Share this answer
 
v2
Comments
Sander Rossel 12-Nov-11 4:22am    
That's the same answer as solution 1... Static variables are a bad idea (read solution 1) for this problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900