Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading form fields from Server.Transfer ???

Status
Not open for further replies.

baden

Programmer
Feb 6, 2002
125
US
For a user signup process, I have two pages containing forms.

The process is as follows:
User enters data in page 1, the Server.Transfer("page2.aspx", true) to page 2.

On page 2, I can see all the form variables form page one by doing a foreach (string vars in Page.Request.Form) ...

That's fine, but then when I hit the submit button and read the postback data (in Button1_Click(object sender, System.EventArgs e)) to enter to the db, using the same foreach method, all I see are the fields from page 2, and nothing from page 1.

I've tried faking it out by adding this to the form in page 2:
Code:
			if (!IsPostBack)
			{
				// add fields from previous page
				foreach (string fields in Page.Request.Form)
				{
					//if (fields.StartsWith("Txt"))
					//{
						Response.Write("Adding: " +  fields + ": " + Request.Form[fields] + "<br>");
						//Response.Write ("<input type='hidden' name='" + fields + "' value='" + Request.Form[fields] + "'>");
						Response.Write ("<asp:TextBox id='" + fields + "' runat='server' Visible='true'>" + Request.Form[fields] + "</asp:TextBox>");
					}
				}
			}

Even w/o the !IsPostBack it doesn't work.

Can someone assist me with how to do this please?


Thank you.

 
I am not sure why you want to add the controls to the page. I think the problem is that on a post back, you are getting the values of the current form (page2), because the page posts back to itself.

Code:
   foreach (string fields in Page.Request.Form)

Will get the fields on the current form. If it is a postback then you get the current form's fields(page2)

Jim
 

Ok, after page 1 is completed, the server.transfer opens up page 2 - where all the values of page one are listed.

That's great, so I figured that when hitting the submit button on page 2, I would be able to add the all the values.

However, page 2 does not have any declarations in the codebehind for the variables passed from page 1, so I won't be able to access them by fieldname.Text.

I've doe the Page.REquest.Form check and still only the values from page two show up.


Does that clarify it a bit?


Thanks.
 

Well, here's a solution if anyone cares....

The initial problem was saving the variables from page 1 on page 2's PostBack, where only page 2's variables where showing up.

Instead of Server.Transfer() on page 1, set the action of the form to page 2.

In page 2, I created a PlaceHolder control and did the following:

Code:
			if (!IsPostBack)
			{
				// add fields from previous page
				TextBox newTB;
				foreach (string fields in Page.Request.Form)
				{
					// text fields from page 1 are forwarded to this page
					// hidden textbox controls are created to store their values for postback
					// b/c they were not saving on post-back; only step2's form values were kept.
					if (fields.StartsWith("Txt"))
					{
						newTB = new TextBox();
						newTB.ID = fields;
						newTB.Text = Request[fields].ToString();

						PlaceHolder1.Controls.Add(newTB);
					}
				}
			
			}

Now when the Submit button is pressed on page 2 all the fields are available.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top