Data transfer from one form to another

This article gives you short idea of, how to transfer data from one form to another

Any small or large project needs data transfer from one form to another.

Data transfer methods are much easier in ASP.NET (web application) than in C#.NET (Window Based application).
ASP.NET uses their own stateManagement technique

Unlike VB.NET in C#.NET we can not access all forms with it's all controls and values directly.

In this article we cover how to transfer values from one page to another in C#.NET

Below example will clear all idea

I have two form in C#.NET application
1. FormOne having 2 textboxes (Userid and Password) and 1 button (Login)
2. FormTwo having 1 Label

now, My requirement is to show Userid on FormTwo.

it can be done using following ways


Declear a public veriable at formTwo, see the below code

public string szUserId;

Label.Text = szUserId;

now show FormTwo on click on FormOne
By creating object of FormTwo, we can Access global veriable and assign values to it

//create a object of formTwo
FormTwo frmtwo = new FormTwo();

//Access global veriable and assign values to it
frmtwo.szUserId = txtUserId.Text;

//Hide formOne

//show formtwo



Declear value in constructor on formTwo

public string szUserId;

//in formtwo Constructor assign a value to it's veriable
FormTwo (string Uid)
this.szUserId = Uid

Label.Text = szUserId;

on FormOne while creating Object of FormTwo pass the userid value

FormTwo frmtwo = new FormTwo(txtUserId.Text);

Here is the simple ways to transfer the values from one form to another.

Hope it helps all.



Author: Biju26 Aug 2010 Member Level: Gold   Points : 2


using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.IO;
using System.Data;
using Interlace.VKSRETANIUM.DTO;
namespace Interlace.VKSRETANIUM.ILayer
public partial interface ICountry
int Save(CountryDTO objCountryDTO);
int HardDeleteCountry(CountryDTO objCountryDTO);
DataTable Search(string strCodn);

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: