如何在asp.net中的内容页面发布值

时间:2012-10-02 06:31:36

标签: c# asp.net http-post

在我的网络应用程序中我有母版页,它有太多的内容页面,在我的内容页面中,我想将表单发布到其他URL。但它没有以这种方式将值发布到其他页面。

但是当我在没有母版页的简单aspx页面中执行相同的代码时,它运行良好。

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="frmPay">
    <div>

    <!-- Receiver Details -->
    <input type="hidden" name="merchant_id" id="merchant_id" value="xxgxg" >
    <input type="hidden" name="merchant_key" id="merchant_key" value="gxgagag" runat="server">
    <input type="hidden" name="return_url" id="return_url" value="http://www.widget.co.za/payment_finished" runat="server">
    <input type="hidden" name="cancel_url" id="cancel_url" value="http://www.widget.co.za/payment_cancelled" runat="server">
    <input type="hidden" name="notify_url" id="notify_url" value="http://www.widget.co.za/payment_notify" runat="server">

    <!-- Payer Details -->
    <input type="hidden" name="name_first" id="name_first"  value="Bob" runat="server">
    <input type="hidden" name="name_last" id="name_last" value="Smith" runat="server">
    <input type="hidden" name="email_address" id="email_address" value="bob.smith@example.com" runat="server">

    <!-- Transaction Details -->
    <input type="hidden" name="m_payment_id" id="m_payment_id" value="TRN123456789" runat="server">
    <input type="hidden" name="amount" id="amount" value="200.00" runat="server">
    <input type="hidden" name="item_name" id="item_name" value="Widget Model 123" runat="server">
    <input type="hidden" name="item_description" id="item_description" value="Widget Model 123" runat="server">

    <!-- Transaction Options -->
    <input type="hidden" name="email_confirmation" id="email_confirmation" value="" runat="server">

    <!-- Security -->
    <input type="hidden" name="signature" id="signature" value="" runat="server">
        <asp:Button ID="Button1" runat="server" PostBackUrl="https://www.payfast.co.za/eng/process" Text="Button" />
    </div>
    </form>
</asp:Content>

1 个答案:

答案 0 :(得分:0)

您的<form>元素没有action=""属性 - 表单不会去任何地方(或者更确切地说,它将提交到当前URI(无论它是什么))。如果要将值提交到ASP.NET中的其他页面,可以阅读:http://www.codeproject.com/Articles/14092/Cross-Page-Posting-in-ASP-NET-2-0