ASP.NET 4 Form Inside Web Form Page

I am new to programming, but trying to learn. Im running visual studio 2010 with an asp.net webform project using C #. I am trying to implement Paypals now purchase buttons on one of the pages, and the code that is generated is also in the form tags. No matter what button it is, the first button on the page never works, and there is a solid blue line below it. All other buttons work fine. even if I delete it, the next button will be the first on the page, and then it also doesn’t work .... I find out that since all pages are forms and the generated code is also a form, I cannot have a form inside the form. It's right? Is there a way around this ... all I really know is HTML LIL and CSS lil, I'm trying to learn JavaScript, C #, XML, CSS, ASP.NET, as well as Visual Studio.Any help would be greatly appreciated. If someone wants to see what I'm talking about, go to www.curbappealfordummies.net/Packages.aspx. This is the site I work on and the webmaster ... Thanks guys for your help.

+3
source share
3 answers

This is a widespread question, but one of the possible answers is to create a second form that contains the necessary PayPal code.

This is a simplified example ; usually there is the logic necessary to achieve this goal. For example, if the buttons should be contained in the default form in ASP.Net, there must be server and / or client code to connect them to this second form to ensure that it contains the correct hidden values.

In your web form

<form id="form1" runat="server">
<!-- Contents of your server form -->    
</form>
<%=base.GetMarkupOutsideDefaultForm() %>

In CodeBehind Code

public string GetMarkupOutsideDefaultForm()
        {
            //
            // Return the markup needed for a PayPal form, 
            // including javascript needed to automatically submit it.
            // AppSettings can be any configuration object that contains
            // the needed URL (or you can hardcode it)
            StringBuilder sb = new StringBuilder();
            sb.Append( "<form action=\"" + AppSettings.PayPalUrl + "\" method=\"post\" id=\"frmPayPal\" target=\"_blank\">" );

            // add hidden PayPal fields

            sb.Append( "</form>" );

            sb.Append( "<script type=\"text/javascript\">document.forms[\"frmPayPal\"].submit();</script>" );

            return sb.ToString();
        }

If the logic is complex, the second block of code should really be contained in the helper class.

Hope someone goes the right way.

+1
source

I know what you mean. Try adding more

<form action='https://www.paypal.com/cgi-bin/webscr' method='post' target='paypal'></form>

Up.

Example:

<form id="form1" runat="server">
  <div>
    <form action='https://www.paypal.com/cgi-bin/webscr' method='post' target='paypal'>
    </form>
  </div>
  <div>
    <form action='https://www.paypal.com/cgi-bin/webscr' method='post' target='paypal'>
      <input type='hidden' name='add' value='1'>
      <input type='hidden' name='cmd' value='_cart'>
      <input type='hidden' name='business' value='<%# DataBinder.Eval(Container.DataItem, "business_email") %>'>
      <input type='hidden' name='no_shipping' value='0'>
      <input type='button' name='submit' value='Add To Cart' title='Add to Cart Button'>
    </form>
  </div>
</form>

Simple but it works.

Or, if you do not like this idea, try this post:

0
source

Source: https://habr.com/ru/post/1765761/


All Articles