如何绕过为 paypal 按钮嵌入 html 表单 asp.net

发布于 2024-09-11 07:50:37 字数 449 浏览 0 评论 0原文

我有一些在 asp.net 网站上使用 PayPal 的经验,但是这个问题让我真的很困惑。

问题的根源:您无法在页面表单中嵌入 paypal 按钮的 html 表单。

原始解决方案:最初我的网站使用多个 aspx 页面,因此我可以简单地排列我的表单标签,这样它们就不会相互嵌入。

我的网站现在使用一个主 aspx 页面,该页面绘制不同的 ascx 控件。这意味着我无法选择在页面周围排列表单标签,因此需要解决方法。

注意。我到处寻找简单的解决方案,但那里就像一片丛林,贝宝是一场噩梦。我确实在 幽灵表单 这一切都是用 c# 编写的。可能有帮助...

提前感谢您的帮助...

I have some experience of using paypal with an asp.net website, however this issue has me really stumped.

Root of the problem: You cant embed the html form for the paypal button inside your page form.

Original solution: Originally my website was using multiple aspx pages so I could simply arrange my form tags so that they weren't embedded inside one another.

My website now uses a master aspx page which draws in different ascx controls. This means that I do not have the option of arranging the form tags around the page so need a work around.

NB. I have looked all over the place for simple solutions but it is a jungle out there, paypal is a nightmare. I did find something on ghost form which is all in c#. Might help...

Thanks in advance for any help....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

姐不稀罕 2024-09-18 07:50:37

使用他们的 API 提交 PayPal 信息,而不是直接向他们提交表单。

这样您就可以将所有内容保留为单个表单的一部分,并在 PayPal 输入和验证方面添加更多的稳健性。

PayPal:SDK 和下载

Submit the PayPal information using their APIs rather than submitting a form directly to them.

That way you can keep everything as part of a single form and add a little more robustness around the PayPal input and validation.

PayPal: SDKs and Downloads

掩耳倾听 2024-09-18 07:50:37

另一个支付提供商也有这个问题。您可以使用他们的 API,也可以通过以下方式解决此问题:

  • 将结账按钮设为标准图像按钮
  • 运行 ClientScript.RegisterStartupScript() 之类的内容来输出 HTML 和 Javascript。 HTML 应该是具有所有隐藏字段和正确 ID 的实际表单。 javascript 是在页面加载时执行并提交页面的代码。

ClientScript.RegisterStartupScript(Me.GetType(), "PaypalSubmit", "", False)

希望这有帮助,否则您可以使用 Web 服务 API。通过采用这种方法,您将执行回发,输出 HTML 表单(在 .NET 表单之外,因为它位于页面底部),然后依靠 javascript 实际提交它。

Had this issue with another payment provider also. You could either use their API, or you could work around it by:

  • Making the checkout button a standard imagebutton
  • Running something like ClientScript.RegisterStartupScript() to output both HTML and Javascript. The HTML should be the actual form with all hidden fields and proper id. The javascript is code which would execute on page load and submit the page.

i.e. ClientScript.RegisterStartupScript(Me.GetType(), "PaypalSubmit", "<AllMarkUp><GoesHere><script>And.Javascript</script>", False)

Hope this helps, otherwise you could use the web service API. By taking this approach you are performing a postback, outputting the HTML form (outside the .NET form because it is at the bottom of the page) and then relying on the javascript to actually submit it.

清泪尽 2024-09-18 07:50:37

这是对你有用的东西。在您的代码隐藏中:

// Workaround for PayPal form problem
CustomForm mainForm = new CustomForm();
mainForm.RenderFormTag = false;

创建一个覆盖 HtmlForm 类的自定义表单类:

public class CustomForm : System.Web.UI.HtmlControls.HtmlForm
{
    protected bool _render;

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

    public CustomForm()
    {
        //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);
    }
}

Here's something that will work for you. In your code-behind:

// Workaround for PayPal form problem
CustomForm mainForm = new CustomForm();
mainForm.RenderFormTag = false;

Create a custom form class which overrides the HtmlForm class:

public class CustomForm : System.Web.UI.HtmlControls.HtmlForm
{
    protected bool _render;

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

    public CustomForm()
    {
        //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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文