2

How can I pass values from one form to another in Asp.net?

Can you please give me an example?


I got it. Thanks for everyone for replying.

In source i have to write

protected void btnAdd_Click(object sender, EventArgs e)
{
    Session["name"] = textBox.Text;
    Server.Transfer("WebForm1.aspx");
}

and in target i have to write

void Page_Load(object sender, EventArgs e)
{
    answer.Text = Session["name"].ToString();
    Session.Remove("name");
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Royal Pinto
  • 2,869
  • 8
  • 27
  • 39

1 Answers1

7

Client side technology: 1)Query String 2)Cookies

Query String: For SEnding:

string name="abc"; Response.Redirect(" Page2.aspx?name= "+name);

For Getting: On Page2.aspx string name=Response.QueryString.GetValue(" name ");

For cookies you can use Sending: HttpCookie h=new HttpCookie(); h.Name="name"; h.Value="abc"; Response.Cookies.Add(h) ;

Getting: string name = Request.Cookies('name');

Server Side Technology: 1)Session

For Setting: Session["Name"] = "Abc";

For Getting: string str = Session["Name"].ToString();

In Session you can pass any object type.

Waqar Janjua
  • 6,113
  • 2
  • 26
  • 36