Using WebPages Helpers inside ASP.NET Webforms

Now a few helpers are available for usage with Razor Syntax and ASP.NET WebPages or ASP.NET MVC. But those helpers can be used also inside a Webforms application.

For example I find the Paypal helper extremely usefull. Let’s use it inside an ASP.NET Webforms App.

We are downloading the helper and adding it to our project in Visual Studio. I will use a C# Web Application Project.

The helper requires some initialization. If we were on WebPages we would do that at _AppStart.cshtml but now we are doing it at Global.asax inside Application_Start method.

PayPal.Profile.InitializeBMProfile("[API Username]", "[API Password]","[API Secret]", "sandbox");

Then we head back to our page and write the following code :

<p>    Here is a PayPal button.</p><p>    <% var btn = PayPal.AddToCartButton.Create(Business: YourBusinessEmailAccount,                                                ItemName: "An item name", Amount: "100.00");  %>    <a href='<%= btn.EmailLink %>'>        <%= btn.WebSiteCode %></a></p>

And this is what we get:

image

So simple.

Be careful. The code above is to demonstrate how to use a helper inside an ASP.NET Webform application.

It is a really bad example when it comes to PayPal API. The code above every time the page is loaded it creates an AddToCart button.So BE careful again!

Cheers!

kick it on DotNetKicks.com

4 Comments

Add a Comment (gravatar-enabled)