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

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");
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x