May 2008 Archives

The Wonders of ASP.NET & C#

| No Comments | No TrackBacks

Recently, I've been digging into Microsoft's ASP.NET platform.  As you know [or don't] I've been working with C# heavily for the last two years, but in a WinForms environment.  Before that, I was doing all of my programming using LAMP.. PHP, HTML, and JavaScript - by hand, no doubt.  I have spent countless hours coding JavaScript applications.  Once the "AJAX" revolution hit {I had been doing "AJAX" before the term "AJAX" was coined, using IFRAMES, and other nifty ways of getting data back-and-forth to the server, Prototype.js was a godsend though!} I moved most of my code to JavaScript, and used PHP as a simple backend for delivering JSON formatted packets of information to the client.  Instead of having a bunch of mixed code, I moved closer to the MVC model with a lot of separation.

Since there's a [business] need for me to move back into Web Development, I convinced the 'uppers' that it would be a wise investment to look into ASP.NET for creating our solutions.  There has been a lot of grief because of that, but in my opinion -- it's a better platform, and there is no doubt in my mind about that.  I am so incredibly impressed with how the .NET model works.. and if in practice, how it is in theory works out the way that I think it will, it will make us deliver better products, in a shorter amount of time.  I'm currently teaching our designer how the model works, and how to effectively use it.  He'll be able to produce me 'ready-designer-made' files and all I will have to do is plug in the functionality in the code-behind model, and make sure that things work.

Just simply writing an AJAX type-of function in ASP.NET is 100x easier than what I would have to do 'the old fashioned' way using PHP & JavaScript.  See below:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:ListBox AutoPostBack="true" ID="ListBox1" runat="server" onselectedindexchanged="ListBox1_SelectedIndexChanged" Width="343px"></asp:ListBox>
        <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" ontextchanged="TextBox1_TextChanged" Width="242px"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" Width="102px" />
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label" BackColor="#FFFFCC"></asp:Label>
        <br />
    </ContentTemplate>
</asp:UpdatePanel>

Above is a sample of how AJAX is done is ASP.NET 3.5.  Everything just worked, and on the first try.  I'd type something in the search box, hit the button, and my listbox would be populated with data from the server.  That would have taken me quite a bit more time to do if I had to code everything manually.

However, I am not happy with this model.

There exists a far superior one.

It's called.

Gaia Ajax Widgets {Gaia Ajax Widgets}.

I've mentioned it before in my Dev Tools.  I work closely with the core developers, learning, working with, suggesting, and sometimes working on the product.  It turns the ASP.NET world upside down!!  Fortunately, I've had the opportunity to work with their controls from their as-yet unreleased version.  They are TERRIFIC.  In the above example, the JavaScript that is sent to the browser from the .NET engine is over 6,000 lines of code.  With Ajax Widgets, only about 200 or so.

To recreate the above example:

<gaia:ListBox .../>
<gaia:TextBox .../>
<gaia: Button.../>

Now, their controls are much richer as well.  Instead of having to rely on the user pressing the button to pass their results to the server, I am able to do something LIKE the following:

<gaia:TextBox InputTimeLimit="200" OnTimerTick="PopulateListBox"/>

The above is not exact, I'm paraphrasing because I do not have the parameters right in front of me.  Simply though, I am telling the control that 200ms after the user has last entered a key, fire off a server side event.  My Codebehind would look something like this:

protected void PopulateListBox() {

string input = TextBox1.Text;

// Do some sort of searching here

foreach(...) {

ListBox1.Items.Add(...);

}

}

The server would populate the listbox, and the results would be instantly transmitted to the client.

This is a much cleaner, and simpler than using Microsoft's AJAX model.  Less code, less confusion, faster development, better quality.  The data that is sent back to the listbox by the way.. instead of what Microsoft does which is send basically the .innerHTML to a control (<select..><option><option><option>...) this sends only the *data* and the JavaScript that AjaxWidgets wrote parses it and populates the listbox.  This could mean substantially less time for the client to wait while fulfilling a large request.

There are a million other controls, and they are all top-notch.  There is no way I could do in PHP/HTML/JS what I could do with ASP.NET/C#/Gaia Ajax Widgets in the same amount of time.  I would have a complete, simple, entire application done before I was even done coding a login page in PHP. 

In my opinion, ASP.NET is a better platform and with the right tools - can kick ass over any other development language, especially for rapid prototyping.

- Matthew

About this Archive

This page is an archive of entries from May 2008 listed from newest to oldest.

April 2008 is the previous archive.

June 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.