Posting ASP.NET page variables to another page

You know when you don’t do something for a long time, and even though it’s really simple, you completely forget how to do it? In this case, I just wanted to post a form from one ASP.NET page to another and view the resulting POST variables. Why? To impress the ladies.

On Page 1, I have this stunningly eloquent code:

<asp:TextBox ID=”txtValue1″ Text=”1″ runat=”server” />
<asp:TextBox ID=”txtValue2″ Text=”2″ runat=”server” />
<asp:TextBox ID=”txtValue3″ Text=”3″ runat=”server” />
<asp:Button ID=”btnSubmit” PostBackUrl=”~/Callbacks/PayPal.aspx” Text=”Submit” runat=”server” />

The important piece of information in that junk is the PostBackUrl property on the Button. That tells ASP.NET where to deliver your very important information, if that important information isn’t going to be on the same page.

And on Page 2, I have this equally eloquent code:

protected void Page_Load(object sender, EventArgs e)
{
string itemName = string.Empty;

for (int i = 0; i < Request.Form.Count – 1; i++)
{
itemName = Request.Form.AllKeys[i];
Response.Write(“<br />” + itemName + ” : ” + Request.Form.GetValues(i)[0]);
}
}

Feel free to use this code for all your important, top secret government and banking applications.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: