WebRef.eu  - Internet Marketing and Online Business Resources  

Home / Site Map | Contact


How to Submit Form POST data in ASP.net

The classic ASP method for submitting form data via POST cannot be used in ASP.net.

Instead, one way to to submit form data in ASP.net is using storing in Context and then Server.Transfer. You have to write your own method for the OnClick event of your form as follows:

<%@ Page Language="VB" %>

<script runat="server">
Sub TransferToAddReviewForm(ByVal sender As Object, ByVal e As EventArgs)
'Storing in Context
Context.Items("ProductId") = ProductId.Text

End Sub
< /script>

<!-- This example uses a hidden form field -->
< asp:TextBox ID="ProductId" runat="server" Visible="false" Text="15" />

<asp:Button ID="Button1" Text="Add a Review" OnClick="TransferToAddReviewForm"
runat="server" />

<asp:Button ID="Button2" Text="View Reviews" OnClick="TransferToViewReviewsPage"
runat="server" />


Then in the receiving page (in this case review-add.aspx), you collect the variable value as per below. Note we check that it's not a PostBack before collecting the variable so we don't get an error if the receiving page (review-add.aspx) has to get posted back to itself (quite likely in ASP.net):

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

If Not (IsPostBack) Then
LabelProductId.Text = Context.Items("ProductId").ToString()
End If

End Sub


Low Prices UK Shopping

Compare Prices
at LowPrices.co.uk

Home / Site Map | Contact

All Content ©2020 WebRef.eu