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));
Feel free to use this code for all your important, top secret government and banking applications.