2014-03-26 30 views
0

我想在我的.aspx頁面中實現一個貝寶付款。我在我的頁面中有以下html:在ASP.NET頁面中的POST表格

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
    <input type="hidden" name="cmd" value="_xclick"> 
    <input type="hidden" name="hosted_button_id" value="19218"> 
    <input type="hidden" name="rm" value="2"> 
    <input type="hidden" name="business" value="<%= ConfigurationManager.AppSettings("BusinessEmail").ToString%>"> 
    <input type="hidden" name="item_name" value="<%= "CityBits Gold " & listplans.SelectedItem.ToString & " listing plan for " & trim(txttitle.text)%>"> 
    <input type="hidden" name="item_number" value="<%= HiddenFieldid.Value%>"> 
    <input type="hidden" name="amount" value="<%= listplans.SelectedValue%>"> 
    <input type="hidden" name="currency_code" value="EUR"> 
    <input type="hidden" name="return" value="<%= ConfigurationManager.AppSettings("ReturnUrl").ToString & "?requestID=" & HiddenFieldid.Value%>"> 
    <input type="hidden" name="cancel_return" value="<%= ConfigurationManager.AppSettings("CancelUrl").ToString%>"> 
    <input type="hidden" name="no_shipping" value="1"> 
    <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt=""> 
    <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> 
</form> 

在我的aspx頁面中,當我點擊貝寶按鈕時,它只是刷新頁面。當我將完全相同的代碼(當然是實際值)放在一個純HTML文件中並單擊該按鈕時,它會根據需要將我重定向到PayPal。我已經嘗試使用輸入的實際值,就像在html頁面中一樣,但它仍然不起作用。

如果它很重要,我有更新我的網頁面板,但這種形式不在裏面。

有人知道我在做什麼錯嗎?這可能是愚蠢的,但現在讓我頭疼2天!

+0

快速破解:在開始處放置一個關閉窗體 - >'

Aristos

+0

@Aristos其實我在這個頁面上使用了一個masterpage,所以我不能在這樣的開始關閉表單。之後我還有其他的asp.net元素。 – user2916280

回答

1

這裏的問題是ASP.NET頁面的工作方式。 ASP.NET始終只在頁面上使用一個大表單,並在引入第二個表單時開始執行各種技巧。

但是,您可以在您的情況下使用的是Button控件及其PostBackUrl屬性。試圖將數據發佈到PayPal時

<form target="paypal"> 
    ... 
    <asp:ImageButton runat="server" ID="PayPalSubmit" 
        PostBackUrl="https://www.paypal.com/cgi-bin/webscr" 
        ImageUrl="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" /> 
</form> 
+0

我實際上已經嘗試過(抱歉不提),但是由於某種原因,當它重定向到PayPal時,我收到了以下消息:此時,我們無法處理您的請求。請返回到[email protected]並嘗試其他選項。 – user2916280

+0

@ user2916280,這聽起來不像是一個ASP.NET問題。使用提琴手或螢火蟲,檢查請求,然後諮詢貝寶文檔以查看請求是否符合PayPal的預期 – Andrei

0

這是一個衆所周知的問題,與ASP.NET表單:它會正確處理的內在形式,收集所有參數和執行職位。下面是我使用所有的電子商務Web窗體應用程序時一個非常酷的解決方案:

http://jerschneid.blogspot.com/2007/03/hide-form-tag-but-leave-content.html

這裏是兩個人的博客文章擴大使用HtmlForm控件的自定義版本的傑里米·施奈德的想法:

http://codersbarn.com/post/2008/03/08/Solution-to-ASPNET-Form-PayPal-Problem.aspx

http://codersbarn.com/post/2008/03/27/Integrate-PayPal-Checkout-Button-with-ASPNET-20.aspx

遠離採用雙層形式的標籤,JavaScript和其他黑客了。

using System; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 

/// <summary> 
/// This is a special form that can _not_ render the actual form tag, but always render the contents 
/// </summary> 
public class GhostForm : System.Web.UI.HtmlControls.HtmlForm 
{ 
    protected bool _render; 

    public bool RenderFormTag 
    { 
     get { return _render; } 
     set { _render = value; } 
    } 

    public GhostForm() 
    { 
     //By default, show the form tag 
     _render = true; 
    } 

    protected override void RenderBeginTag(HtmlTextWriter writer) 
    { 
     //Only render the tag when _render is set to true 
     if (_render) 
      base.RenderBeginTag(writer); 
    } 

    protected override void RenderEndTag(HtmlTextWriter writer) 
    { 
     //Only render the tag when _render is set to true 
     if (_render) 
      base.RenderEndTag(writer); 
    } 
}