From technology to politics to video games; these are the random thoughts of a geek with too much time on his hands
Revelations I've Had While Trying To Learn ASP.NET
Published on January 27, 2005 By Zoomba In Websites
Alright, at work I've been told I have to build a web tool that takes a 40 question survey, analyzes the answers given, then based on the answers generate custom content from a large stack of documents. Fair enough. The catch is I have to do it in ASP.NET, and not PHP because ASP.NET is supported by IT whereas PHP is not (despite the fact that IT runs serveral PHPNuke sites, which obviously relies on PHP).

So, I've been trying to learn ASP.NET for the purpose of building this tool. In the short time I've been at this, I've been frustrated by the needless layers of complexity Microsoft introduces into the process of building a dynamic web page. This is the first part in what will likely be a multipart series of articles in which I compare and contrast PHP and ASP.NET. This will be the foundation for a later report I've been asked to write for the head of the Architecture Practice here to show the relative merits of adding PHP to the supported list.

I admit I'm biased here by the fact that I am familiar with one, but not the other. However, I'm going to try and limit my points to items where there is a clear difference between the two... Each of these articles will compare and contrast the two on a specific problem I'm encountering.

1.) How Much Do You Need To Know?
Ok, lets say you want to create the most basic dynamic page. All you want to do is have a form with a text field that you fill in with whatever text you like, and when you click submit, it loads a page that displays that text and nothing more. No databases, nothing complicated. How much do you need to know to do that in either language? Well, let's take a look...

PHP
Languages Needed: PHP, HTML
Solution method: The form page is simple HTML form, all it does is POST to the target php page to display the text. The target PHP page grabs the posted field, assigns it to a variable and prints it to the screen. Lines of code in PHP... 2.

ASP.NET
Langauges Needed: ASP.NET tags, HTML, VB.NET/C#/Whatever your desired .NET language is... so in essence, 3 languages
Solution method: Well, in ASP.NET, you don't POST to other pages, you POST back to the same form, write a button click event that processes the information and assigns it to a variable. Then either redirect everything to a second page, or load the variable as a label somewhere on the original page. Lines of code? Too damn many. I still haven't figured this out properly. I know for damn sure it's a lot more than 2 lines though.

Comments
on Jan 27, 2005
It's actually just one line of code in .net

Here is the first page just regular html.










WebForm.aspx:






WebForm






on Jan 27, 2005
oops, can't post the html code. Try again. Just replace the number sign with the less then and greater then signs

test.htm:
#html#
#body#
#form id="boo" name="booo" action="WebForm.aspx"#
#INPUT id="Text1" type="text" name="Text1"# #INPUT id="Submit1" type="submit" value="Submit" name="Submit1"#
#/form#
#/body#
#/html#

WebForm.aspx:
#%@ Page language="c#"%#
#!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" #

#html#
#body#
#%=Request["Text1"]%#
#/body#
#/html#
on Jan 27, 2005
BIG cookie for you! I couldn't find that anywhere on the ASP.NET sites I found and it wasn't in my huge ASP.NET book. Thank you for saving me from the past few hours of frustration!!
on Jan 28, 2005
Excuse me?
on Jan 29, 2005
Here is something, if you plan on using databases. ASP you have to pay for each and every connection to the database Per user. In PHP, it's absolutely free! Microsoft just wants you to pay for a liscense for each connect on top of the software cost. Just think, one person alone can probably suck up almost 10 connections or more depending on how your server is setup. My suggestion is go with PHP if you want to learn something.
on Jan 29, 2005
The .Net Framework creates a user called ASPNET...set up your web app/database to utilize this user. You only need ONE user to make your database available on the web and you DON'T have to pay for it.

P.S. Put the connection to the database in the web.config file or leverage 'PostBack' and you only need ONE connection.
on Jan 30, 2005
O' so there is a diffrence between ASP and ASPNET. Because when I had a class on ASP, I was told that you had to pay for a liscense for each connection to the database.
on Jan 30, 2005
That all depends on which backend database you are using and what type of licensing package purchase. For SQL Server, you can get licensing on a "Per Server/Processor" basis, or "Per Connection". All depends on what kinds of money a company wants to shell out. I would assume Oracle has a similar licensing plan.
on Jan 30, 2005
I always considered ASP.NET to be the replacement for ASP. They are similar in some respects and you can still code classic ASP (as well as javascript) within your app but why would you want to? There are an abundance of very cool .Net controls out there or you can even write your own. In fact, I am in the process of rewriting all of our company's telnet applications (which access datasets on our mainframe - old TN3270 apps) in ASP.Net with a SQL backend. 5 years ago I would not even have considered such an undertaking with the tools available at the time (such as ASP). Total development/conversion time about 18 months which includes a few months of school work.
on Jan 30, 2005
I know and love PHP, but have no experience in ASP, so I can't make a fair comparison between the two. But something confused me in the article. Why two lines in the PHP page? Wouldn't it simply be:

<?php echo $_POST['form_element_name'] ?>

Only one line, right?
on Jan 30, 2005
As far as doing it in two lines, because I'm rarely just redisplaying a passed variable, I usually assign it to a new variable from the POST data and then manipulate/display that information. Makes it a bit more readable too IMO.
on Jan 30, 2005
Can't wait to see further articles on this topic- unexpected side-effect is collaboration and sharing of techniques. Looks like everyone will benefit.
on Jan 30, 2005
I agree that this should be interesting.