Article

Home » Server-side Coding » ASP & .NET Tutorials » Debate - .NET V. PHP: Top 6 Reasons to Use .NET

About the Author

Mattias Johansson

author_mattiasJ Mattias is a passionate Web developer with a taste for elegance and simplicity, and made his first Website at 14 years of age. His spare time is spent acting or drinking strangely flavoured cappuccinos.

View all articles by Mattias Johansson...

Debate - .NET V. PHP: Top 6 Reasons to Use .NET

By Mattias Johansson

September 5th, 2002

Reader Rating: 6

Page: 1 2 Next

Welcome to another SitePoint Debate. Today, daggers are drawn over that long-running battle of the technological titans -- Open Source and Microsoft.

Specifically, we ask "Does .NET mean the end for PHP?" Judge for yourself...

First of all, I'd like to clarify that I'm a PHP guy. I've coded in PHP for the last 2 years, and all my current sites are built in PHP and MySQL. I've never liked ASP during my time as a Web developer, and still dislike it. However, ASP.NET is an entirely different matter, which I'm learning now, with great enthusiasm. This article is targeted at PHP developers, designed to show some of the cool stuff ASP.NET has to offer. And after all, there's no reason you can't know both ASP.NET and PHP.

What is the .NET Framework?

The .NET Framework consists of two main parts:

  1. the CLR (the thing that runs code), and

  2. a hierarchical set of class libraries (Think PHP functions + the PEAR libraries, extend them a little, and have them organized in a very nice hierarchical structure). Included in those class libraries are ASP.NET, ADO.NET (a data access system) and Windows Forms (classes for building windows apps).

The CLR can run code written in any language that's adapted to .NET, and can run it on any operating system that has a version of the CLR. In other words, kind of like Java that doesn't have to be written in Java.

An Example: The Web Forms Framework

ASP.NET has a kind of templating system on steroids called Web Forms. I mention this first because it's this system that got me interested in ASP.NET in the first place, and is, in my opinion, the best feature of ASP.NET. There's nothing like it in PHP yet, to my knowledge. It goes something like this:

<select id="ColorSelect" runat="server">
 <option>SkyBlue</option>
 <option>LightGreen</option>
 <option>Gainsboro</option>
 <option>LemonChiffon</option>
</select>
<span id="Span1" runat="server">Some text.</span>

Notice that the above is just ordinary HTML, with the addition of the runat="server" attribute in the <span> and <select> tags. Now, to add an option to this selectbox, you would include the following in your ASP.NET code (which, by the way, can be separated completely from the HTML):

ColorSelect.Items.Add('AzureBlue');

And to manipulate the <span> tag, you would do this:

Span1.Style["background-color"] = "red";
Span1.InnerHTML = "Changed text!";

...and the system outputs 100% valid XHTML to the browser:

<select id="ColorSelect">
 <option>SkyBlue</option>
 <option>LightGreen</option>
 <option>Gainsboro</option>
 <option>LemonChiffon</option>
         <option>AzureBlue</option>
</select>
<span style="background-color: red;">Changed text!</span>

Besides the fact that this is very cool, it also makes collaboration with the clueless HTML/Designer guys much easier. This is only a very simple example of what the Web forms framework is capable of, and if you're interested, you can check out more examples in the ASP.NET Quickstart tutorials over at GotDotNet.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links