Paypal 表单破坏了我的 ASP.NET webforms 布局 ->如何解决?

发布于 2024-12-04 08:21:04 字数 549 浏览 0 评论 0原文

我是一名学生,正在用asp.net 制作一个简单的网站。我的问题是,我希望在其中一个页面上集成 Paypal,但是 asp.net 有 荒谬

正在进入我的方式。我正在使用 blueprint css 构建一个简单的站点布局,这是一个非常基本的三列布局。然而,我需要我的主要内容部分能够使用贝宝表单(立即购买按钮),并且网站的其他区域能够使用用户控件,我认为这需要将它们包装在那个令人恼火的表单标签中。事实上,我希望在网站主要部分的顶部有一个站点地图路径控件:一些非常基本的东西。我怎样才能做到这一点?我的问题是:我无法将 Paypal 按钮放入表单中,并且我不知道如何将第四个 div 移动到位。我什至不确定 div 和表单如何相互堆叠。

我可以帮忙吗?

出现问题的页面是:http://clubofpep.org/sandbox/sandbox_Alumni.aspx

I am a student who is doing up a simple website in asp.net. My problem is, I wish to integrate Paypal on one of the pages, but asp.net has the ridiculous <form runat="server"> that is getting in my way. I am building a simple site layout using blueprint css, a very basic three-column layout. However, I need my main content section to be able to use the paypal form (buy now button), and the other areas of the site to use user controls, which I presume requires them to be wrapped in that irritating form tag. In fact, I would like to have a sitemap path control at the top of the main section of the site: something very basic. How might I achieve that? My problem is: I can't put the Paypal button in the form, and I don't know how to shift a 4th div into place. I am not even sure how divs and forms stack on each other.

Could I have some help please?

The page with the problem is: http://clubofpep.org/sandbox/sandbox_Alumni.aspx.

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

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

发布评论

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

评论(2

罗罗贝儿 2024-12-11 08:21:04

与普遍看法相反,您可以在 ASP.Net Web 表单页面上拥有多个表单。您不能做的是拥有多个带有 runat="server" 的窗体,在 ASP.Net 主窗体内嵌套第二个窗体,或在主窗体外部使用 asp.net 服务器控件。

因此,要将单独的 Paypal 表单与 ASP.NET Web 表单页面的其余部分集成,您必须确保可以将其放在页面上所有 ASP.NET Web 控件之前或之后。页面,然后编辑 aspx 标记以确保您的 paypal 表单完全在 asp.net 表单之外。

另一件事是,快速网络搜索显示大量为 ASP.NET 编写的 Paypal 控件,这些控件将与提交付款所需的 ASP.NET 表单配合使用。你总是可以尝试其中之一。

Contrary to popular belief, you can have more than one form on ASP.Net webforms pages. What you cannot do is have more than one form with runat="server", nest a second form inside ASP.Net's main form, or use asp.net server controls outside the main form.

Therefore, to integrate a separate paypal form with the rest of an asp.net webforms page, you have to make sure that you can put it either before or after all of the asp.net web controls on the page, and then edit the aspx markup to make sure your paypal form is completely outside of asp.net's form.

The other thing is that a quick web search shows a multitude of paypal controls written for asp.net that will work with the required asp.net form to submit the payment. You could always try one of those.

っ左 2024-12-11 08:21:04
namespace CustomForm
{
    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);
        }
    }
}

用法:

ASPX:

<%@ Register TagPrefix="CF" Namespace="CustomForm" Assembly="CustomForm" %>
<body>
    <CF:GhostForm id="mainForm" runat="server">
    ...
</body>

<img src="https://www.sandbox.paypal.com/en_US/i/btn/btn_xpressCheckout.gif"> <asp:Button ID="checkoutBtn" runat="server" OnClick="CheckButton_Click"
    Text="Checkout" Width="100" CausesValidation="false" /> 

代码隐藏:

protected void Page_Load(object sender, EventArgs e)
{
    ...
    // Workaround for PayPal form problem
    GhostForm mainForm = new GhostForm();
    mainForm.RenderFormTag = false;
    // Go ahead and submit to PayPal :)
}
namespace CustomForm
{
    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);
        }
    }
}

USAGE:

ASPX:

<%@ Register TagPrefix="CF" Namespace="CustomForm" Assembly="CustomForm" %>
<body>
    <CF:GhostForm id="mainForm" runat="server">
    ...
</body>

<img src="https://www.sandbox.paypal.com/en_US/i/btn/btn_xpressCheckout.gif"> <asp:Button ID="checkoutBtn" runat="server" OnClick="CheckButton_Click"
    Text="Checkout" Width="100" CausesValidation="false" /> 

Code-Behind:

protected void Page_Load(object sender, EventArgs e)
{
    ...
    // Workaround for PayPal form problem
    GhostForm mainForm = new GhostForm();
    mainForm.RenderFormTag = false;
    // Go ahead and submit to PayPal :)
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文