WebRef.eu  - Internet Marketing and Online Business Resources

Home | Contact Us

Google
 

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

Server.Transfer("review-add.aspx")
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()
'Page.DataBind()
End If

End Sub

 



Join Top Affiliate Networks Join Top Affiliate Networks >>>



Paid On Results

Expansys








Home | Contact Us

All Content ©2006 WebRef.eu