Suppose i have two text fields in one page, one for name and another one for age.
When i click the submit button those values should appear in another page. Can any one give the example for that one.. i am totally confused.
please help me Thank you
Suppose i have two text fields in one page, one for name and another one for age.
When i click the submit button those values should appear in another page. Can any one give the example for that one.. i am totally confused.
please help me Thank you
On
Put this code to your submit button event handler,
private void btnSubmit_Click(object sender, System.EventArgs e) { Response.Redirect("AnotherPage.aspx?Name=" + this.txtName.Text + "&Age=" + this.txtAge.Text); }
Put this code to second page page_load,
private void Page_Load(object sender, System.EventArgs e) { this.txtBox1.Text = Request.QueryString["Name"]; this.txtBox2.Text = Request.QueryString["Age"]; }
On
You have a couple of options. **
1. Use Query string.
(Cons)
- Text might be too lengthy
- You might have to encrypt/decrypt query string based on your requirement
(Pros)
- Easy to manage
2. Use Session
(Cons)
- May increase processing load on server
- You have to check and clear the session if there are too many transactions
(Pros)
- Values from different pages, methods can be stored once in the session and retrieved from when needed
MSDN has a page on this, How to: Pass Values Between ASP.NET Web Pages:
For your scenario, it sounds like using POST is the way to go, since you have textboxes on the first page. Example:
First page:
Notice the
action="WebForm2.aspx"which directs the POST to the second page. There's no code-behind.Page 2 (receiving page):
Notice the
EnableViewStateMac="false"attribute on the Page element. It's important.The code-behind, grabbing the values using a simple
Request.Form():That should work... :)