The Differences of ASP.NET Forms and Windows Forms in a Nutshell
Posted by triaslama on June 24, 2008
I think its quite interesting if we compare two things that has equalities and differences. Now we will talk about Forms (WebForms and WinForms).
As we already know WebForms uses browser as presentation (ASP.NET Forms is no exception) and Windows Forms has its own presentation. So we may agree that WebForms has the strength through its availability and WinForms through its rich user interface.
In this post I will talk about the differences, what I get from both forms (ASP.NET Forms and Windows Forms) at a glance. I hope this post not tedious for those who already familiar with ASP.NET and Windows Forms.
An ASP.NET Form inherits Page class (contained in System.Web.UI namespace). Look at the following example:
Presentation page (Welcome.aspx):
This is the code behind (Welcome.aspx.cs):
I use C# as server side language, and note that HelloWorldClass must be marked as partial class and it inherits Page class.
A Form of Windows Forms inherits Form class (contained in System.Windows.Forms namespace). Look at the following example:
If you are new to ASP.NET (web application in general), maybe you are wondering with what is called Postback. In Wikipedia, postback defined as follow “A Postback is an action taken by an interactive webpage, when the entire page and its contents are sent back to the server for processing.” Desktop application not recognize Postback term.
Suppose that I have a form with Combo Box (Drop Down List) inside it. I want to take an action everytime selected value of Combo box / Drop Down List changed. In Windows Forms we just do the following:
To do the such thing in ASP.NET Form, we need postback! Look at the following code:
Here the code behind for above code:
<asp:DropDownList id="ddl" OnSelectedIndexChanged="SelectedChanged" AutoPostback="false" runat="server">
In Windows Forms we must specify the Location property for a control, if we forget it, the controls inside a WinForms will overlap each other. Its not the case with WebForms because the position follow the document (ASP.NET page) flow.
In Windows Forms we govern the looks and feels of Form through property of each control (e.g. Font, Color, BackColor, etc.). There is one static method in Windows Forms, use it when we want to apply visual styles in our Form, the name is Application.EnableVisualStyles(). This method is useful enough just call it before Application.Run() and then you will see the different is obvious!
In ASP.NET Form we can use CSS file to handle the looks and feels of our web page.
That’s some of differences between ASP.NET Forms and Windows Forms which I know. I have no doubt that still many differences between them that uncovered here.