asp pages and paypal button - asp.net

I have an asp.net page in 3.5 that I have a pay pal button on but when I click on the button it just refreshes the page. I think I need to encapsulate the paypal button in something so it is not trigging the refresh but goes to pay pal.
Anyone know a solution? Can I use an updatePanel or iframe?

I had this same issue once, I just used the following code for my button:
<asp:ImageButton ID="btnPayNow" runat="server" ImageUrl="~/images/Purchase/payNowButton.jpg" PostBackUrl="https://www.paypal.com/cgi-bin/webscr"/>
Hope that helps!

Paypal pay now buttons as generated by paypal site have their own form tags in. ASP.Net pages are generated with the whole page within a form, so you now have a form within a form which wont work. If you opt for a paypal hosted button you can have code like this within the asp.net page which will work:-
<input type="hidden" name="cmd" value="_s-xclick"/>
To order the item name for £99
<input type="hidden" name="hosted_button_id" value="note to programmer-this value is generated by paypal"/>
<asp:ImageButton ID="Button2" runat="server" PostBackUrl="https://www.paypal.com/cgi-bin/webscr" ImageUrl="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" ImageAlign="AbsBottom" />
I know this is an old question, but I hope this helps someone else.
also, take a look here for a discussion of the issues and other possibe solutions.
http://www.blackbeltcoder.com/Articles/ecommerce/quick-and-dirty-buy-now-buttons-in-asp-net

I would recommend you to use the PayPal Developer Toolkit for this. They're having a lot of good code samples and how to implement PayPal the best in your ASP.NET page.

Related

Editing a Database Entry

I'm creating a website with ASP.net that, if you are logged in as an admin, you can edit the current pages text (this way I don't have to update the website all the time just for small changes, I can just edit the page myself while its online). All the page data is stored in a SQL Database table. Each entry is simply "ID" and "PAGECONTENT". Now, I used a SQLDataSource to get the data and put it into a FormView on my page. This all works. I made a button that is only visible if I'm logged in as the site-admin. I need to make it so when I click the button, the textlabel displaying the page content turns into a TextArea for me to edit, then I can click a "Done" button and have it update it to the Database table. I can do the updating part, I just don't know how I'm supposed to display the text in an editable manner...
You need something called a Rich Text Editor control. This will give you a Microsoft Word style interface with a toolbar etc and it will parse the html for you that you have stored in the database.
There are lots of free ones out there. A commonly used one is the one included in the Ajax Control Toolkit.
You should use nuget to install the latest Ajax Control Toolkit into your project.
There are lots of tutorials out there which explain how to use this control:
http://www.google.co.uk/search?q=asp.net+ajax+control+toolkit+htmleditor
The POST scenario: Just like you have a button that is visible only when you're logged as the site admin, have a textarea only visible when you click the edit button and have it saved when you click the done button.
A good practice would be to have a dedicated page for the edition of your db entry unless you're working with an ajax interface. It can get complicated and unsafe to POST when changing from a detail view to an edit view and to POST again when saving. That's just an idea.
The GET-then-POST scenario: have a dedicated edit page for your db entry. Let's say: /editpage.aspx?id=1. Have a done button on that page that postback and save your work.
Good luck.
http://www.w3schools.com/aspnet/control_htmltextarea.asp
maybe this is what you are looking for.
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
p1.InnerHtml = "<b>You wrote:</b> " & textarea1.Value
End Sub
</script>
<html>
<body>
<form runat="server">
Enter some text:<br />
<textarea id="textarea1" cols="35" rows="6" runat="server" value="PUT_YOUR_TEXT_HERE_to_prepopulate_the_Data" />
<input type="submit" value="Submit" OnServerClick="submit" runat="server" />
<p id="p1" runat="server" />
</form>
</body>
</html>

Is nested <form> possible?

in a content page of an asp.net web page, i would like to include the "paypal" button "Pay Now".
So, i've a master page, and a content page.
In my content page i copy-paste paypal code.
In particular i use a "modalpopupextender" to permit my user to buy the object.
The problem is... it not work.
So my hypotheses are:
I'm not sure, but i think i can't use a nested <form action>
If not the first, maybe i can't use a <form action> into a modal popup ?
someone can suggest me an "elegant" solutions to solve this ?
Thank you ...
EDIT: in particular, what i'm trying to do is to permit to sell from a website.
I've a master page, and a content page.
Obviously in master page i've the classical "form action" .
Then i'm gone to paypal and got this code: "
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<table>
<tr><td>
<input type="hidden" name="on0" value="Annuncio Premium">Annuncio Premium
</td></tr>
<tr><td>
<select name="os0">
<option value="Premium 1">Premium 1 €1,00</option>
</select>
</td></tr>
</table>
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="encrypted" value="-----BEGIN ">
<input type="image" src="https://www.paypal.com/it_IT/IT/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - Il sistema di pagamento online più facile e sicuro!">
<img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1">
</form>
So i've pasted it into my content page ... as it... without changing.
In particular i've pasted it, into a panel, that will show whith a "modalpopupextender".
It works. But what it not work is when i click the paypal "Buy Now" button.
My web page don't redirect to paypal, modalpopup disappears and nothing happens.
I had this exact issue too and couldn't believe that PayPal had not provided some sort of solution for .NET developers!!
Here is how I solved it:
<asp:ImageButton ID="btnPayNow" runat="server" ImageUrl="myPayPalButton.jpg"
PostBackUrl="https://www.paypal.com/cgi-bin/webscr" OnClick="btnPayNow_Click"/>
Use an ImageButton or normal button and simply remove the form tags for the PayPal code, leave in the hidden input fields and the data will be posted to the PayPal url!
Nice and easy :)
Ps. The method 'btnPayNow_Click()' does nothing, signature exists but there is no logic in the code I have.
You are quite correct, in that you cannot nest <form>s.
Nor can you use the form action to create a popup - the action attribute is the url to which the form posts to.
You can, however, have many <form>s on the page, so long as they are not nested. Perhaps that will solve you issue.
Can you please describe exactly what you are trying to achieve? It is not clear from your question what the problem is.
If I understand the question correctly, you are trying to create a dynamic HTML popup window which contains a PayPal form. You are having problems because the popup contains a form, but the HTML for the popup is already contained within a form.
If the problem you are experiencing is what I described above, the solution is fairly simple. You need to move all of the HTML for the popup outside of the exiting form element. If you are using CSS to properly lay out your site, it should be possible to display your dynamic popup wherever you need to on the page using relative or absolute positioning. The HTML for the popup need not be contained within another form. It may also be possible (perhaps even necessary) to put the contents of the popup into an iframe, which can be submitted entirely independently from the rest of the page. The semantics of how your popup works would depend on how you need your page to function.
So, to be clear...it is not possible to nest form elements. However, it is also not necessary to accomplish your needs.
EDIT:
To improve the answer above in light of the updated question. You can have multiple content panels on a master page. It should be entirely possible to create another content panel that is outside of your form element in your master page...and place your modal popup inside of this alternative content panel. My above answer would then still apply, as you no longer have nested forms.
You are right in your first hypothese, you can't have nested form tags in a page.
You just have to put the code for the popup outside the form, you can have any number of forms in the page as long as they are not nested.
Dal's answer is correct! (not taking credit with my answer)
I had a similar issue in ASP.NET (4.0) when trying to submit data to SagePay (same as PayPal form posting). I was writing the form fields in dynamically using panels in the code-behind using
Dim Panel As New Panel
Panel.Controls.Add(New LiteralControl("My <input> controls HTML")) '1 control.add per <input> control.
MyDiv.Controls.Add(Panel)
I was writing the whole < form> dynamically also, so when it came to debugging I received no warnings regarding the issue that my entire Site.Master is within a - this is not visible from a .aspx page using the master as a template! It was quite frustrating... Until I read that you cannot have a nested < form>... There are only two alternatives to this:
1) move the form details outside the first that is within my Site.Master from the .aspx page itself. (I didn't like the idea of this, messy messy!)
2) create another control that is NOT a to post my data.
I chose the latter!
<asp:Button id="btn_payment" value="Proceed to Payment" Text="Proceed to Payment" runat="server" PostBackUrl="https://test.sagepay.com/gateway/service/vspform-register.vsp" />
The button posted to SagePay, took my dynamically generated fields (Called from the .aspx page) and as they were already within the from my Site.Master - all worked well! - I hope this helps anyone using dynamically generated HTML with forms.

jQuery validation plugin and .Net WebForm not playing nicely in IE7, works in IE8

Please bear with me. I've got the jQuery validation plugin working beautifully in FF, Opera, Safari and IE8. However, IE7 is giving me problems. Our back-end developer insisted on using .Net WebForm to create the form on the server (at least this is what I think she used, it's .aspx is about all I know - I can post some code if it'll help.) Anyway, in the code her submit button looks like this:
<asp:Button ID="btnSubmit" runat="server" Text="Submit the request" OnClick="btnSubmit_Click" />
and the output (in the HTML) looks like this:
<input type="submit" name="btnSubmit" value="Submit the request" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="btnSubmit" />
However, when I replace her code with a simple <button type="submit" name="Submit" value="submit" class="button">Submit</button> the validation works, the error messages pop up, clouds part, etc. But she says she can't use this. Sigh.
So I guess my question is: how do I get jQuery to play nicely with her approach? I'm using jQuery to add some nice UI touches to the form, such as accordions, the calendar widget, etc. and I wanted this to be the icing on the cake. I'm also very sure that the initiation of the js is well-formed, I get no js errors for extra comma's, etc.
Thanks for whatever help you can provide.
Based on the javascript that is emitted in the button's onclick event ("if (typeof(Page_ClientValidate)....."), it looks like you are mixing ASP.NET validation and the jQuery Validate plugin. Try adding CausesValidation="false" to the attributes of the button, thereby forcing it to do a normal form submit, to which the Validate plugin responds.
Does the jQuery require the class to be set to "submit" in order for the jQuery validation plugin to work?
That seems to be the most obvious difference between the html generated by .Net and the html you wrote. If that is the case add 'CssClass="submit"' to asp:button element in the aspx page. This will be converted to 'class="submit"' in the generated html.
<asp:Button CssClass="submit" ID="btnSubmit" runat="server" Text="Submit the request" OnClick="btnSubmit_Click" />

ASP.Net Form send click but nothing happens

I am building a german payment provider into my site.
But when I click on "Submit", nothing happens. Can someone please help me? I think I've looked at it too much and I can't see the forest for the trees anymore...
<form method="post" action="https://www.sofortueberweisung.de/payment/start">
<input name="currency_id" type="hidden" value="EUR" />
<input name="reason_1" type="hidden" value="Zambuu" />
<input name="user_id" type="hidden" value="29593" />
<input name="project_id" type="hidden" value="80145" />
<input type="submit" value="Absenden" />
</form>
Okay, so it's a little bit unclear what I want, it seems:
I have a lot of asp-sites allready, and now I must send, however, the information that is given by the hidden inputs by post-method to the site "sofortüberweisung.de/payment/start".
However I can solve it, it's not nessecary, there is no need for a form-tag, if there is another solution (e.g. with the code behind).
So: How can I send a lot of post information (these here is only an exmaple, in the real site there are a lot more) with code and redirect it to the right site?
If the code you have provided is within a standard ASP.NET form, so that you have nested form tags, try the solutions provided to this Stack Overflow question.
If it is possible to have this page be a simple html form, that is another possible solution.
Your button needs to have the runat="server" attribute set and it might be worth doing the same on your form atttribute.
Also remember in asp.net webforms you can only have one form tag.
I've had this issue a couple of times before where when creating an HTML form inside an ASP.NET form tag, the inner form just wouldn't post out.
One solution for me was to adjust the ASP.NET form tag wrapper for that page (moving the close above the HTML tag).
Another (where I needed ASP.NET controls obove and below the HTML form) was to add an iframe, passing the parameters for the form post to the iframe URL. Using JavaScript, the iframe then used those parameters to post the form to a new window/the parent window. Probably better ways, but it worked for me.

How do I make a key binding/shortcut for an ASP.NET button to postback via that button?

I'm developing what's intended to be a very efficient UI in ASP.NET.
I want my users to be able to hit ALT-A to postback the form via a particular button. In other words, when they hit "ALT A" the form will post back and the event handler/function associated with a particular ASP.NET button control will run.
How can I do this? I have ASP.NET 2.0/3.5. I also have the Telerik control set at my disposal.
-KF
Use the "accesskey" attribute in HTML.
<input type="submit" accesskey="a" value="Submit">
<asp:Button AccessKey="a" runat="server" ....

Resources