ASP 101 - Active Server Pages 101 - Web01
The Place ASP Developers Go!



Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

QUICK TIP:
Image maps 101
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Transitioning To ASP.NET - Part 1 Server Controls

Transitioning To ASP.NET - Part 1 Server Controls

by Carvin Wilson

Overview

The long awaited Active Server Pages .NET (ASP.NET) is the replacement for the current version of ASP. This key component of the new .NET framework has the potential to save organizations time and money by allowing them to establish object-oriented frameworks for the web applications. Microsoft has done an excellent job with automating common web development tasks, but more importantly they have created a tool that gives developers the ability to handle any business problem. In this first article of my transitioning to ASP.NET series, I will give you a basic overview of ASP.NET and server controls.

Big Picture, Little Picture

The arrival of new technology can always be confusing; however, one thing remains the same throughout all languages and platforms-"Fundamentals". I'm going to approach this series by focusing on what developers need to know to get their job done. I feel that the fundamental components of ASP.NET developers need to know are server controls, data access, .NET components, .NET classes, web services, debugging, IDE, how to access legacy ActiveX functions, and application performance. So lets get started!.

So what is the big deal about ASP.NET?

Although there are a lot of changes incorporated into ASP.NET, do not let people scare you into believing your current skills are not good enough. If anything your life will get a lot easier. The greatly improved ASP runtime handles a lot of routine tasks for you. Although there are other major benefits of ASP.NET, here are some that will benefit the majority of development shops.

  • Compiled Pages - A page is compiled into a .NET class the first time it is requested. The runtime engine will detect if any changes are made to the source code and recompile it if necessary. This should give your ASP pages a performance boost. You can optionally specify a class file with your page, if not the ASP runtime will create one for you.

  • More Scripting Choice - You can code your pages with Visual Basic, C#, or JScript. VBScript has been incorporated into the VB syntax.

  • Improved IDE and Debugger - No more Visual Interdev, the entire .NET family shares the same IDE and debugging tools. You will benefit greatly from the feature rich debugging tools for ASP.NET, it is a difference of night and day. The enhanced IDE is a joy to programming with.

  • Server Controls - Server side components automate many common development tasks. These controls can detect the version of the browser and generate the proper HTML and JavaScript code.

  • Platform Independence - The ASP runtime is capable of detecting the browser type of the requesting client and generate the proper HTML or JavaScript code. This has the potential of making your ASP.NET applications platform independent.

  • Separation of Logic - Although you can currently separate business logic and presentation by utilizing ASP and COM. ASP.NET was designed with this concept in mind. It is a lot easier to encapsulate your logic from your presentation. In my opinion, application separation is the key to productivity. It allows you to maximize the abilities of your staff by assigning work accordingly. By creating .NET components and class files, you can maximize code re-use.

  • Backwards Compatibility - Organizations will be able to leverage their existing investments in COM and COM+. ASP.NET applications can interface with legacy COM objects.

So why should I make the switch?

Well my biggest reasons for converting to ASP.NET are encapsulation, inheritance, server controls, and ease of deployment. I enjoy the fact that ASP.NET pages are closely integrated with .NET classes. This offers me the ability to centralize application code within classes that have a smaller footprint than COM. These classes are easier to deploy and capable of deployment over distributed networks. With true inheritance, I can create base classes to maximize code.

As I mentioned earlier, I feel application separation is the key to developing quality applications. It allows your GUI designers to work on the GUI, code warriors to work on the classes and components, and database developers to create stored procedures and views. This ability gives the development manager options and flexibility within the development cycle. Just my 2 cents =)!

Anatomy of ASP.NET Page

I have constructed a very simple ASP.NET page to illustrate how very simple it is.

<% @Page language="C#"%>
<html>
<script language="C#" runat=server>   
private void btnclick_click(object sender, EventArgs e)
  {
    if (cmbcolor.SelectedItem.Text == "red")
      lblcolor.BackColor = System.Drawing.Color.Red;
    if (cmbcolor.SelectedItem.Text == "blue")
      lblcolor.BackColor = System.Drawing.Color.Blue;
    if (cmbcolor.SelectedItem.Text == "yellow")
      lblcolor.BackColor = System.Drawing.Color.Yellow;
    if (cmbcolor.SelectedItem.Text == "green")
      lblcolor.BackColor = System.Drawing.Color.Green;
  }        
</script>
<body>
<form action="intro.aspx" method="post" runat="server">     
<asp:Label runat="server" id="lblcolor" Text="COLOR CHANGE DEMO"/>
<br><br>
<asp:DropDownList id=cmbcolor runat="server">
   <asp:ListItem Value="red">red</asp:ListItem>
   <asp:ListItem Value="blue">blue</asp:ListItem>
   <asp:ListItem Value="yellow">yellow</asp:ListItem>
   <asp:ListItem Value="green">green</asp:ListItem>
</asp:DropDownList>
<br><br>
<asp:Button Text="Click Here" id="btnClick"
   onClick="btnclick_click" Runat=server />
<br>
</form>
</body>
</html>

One new piece of code is the new <%@PAGE %> directive. It controls a lot of functionality for your page. One of the most useful is the ASPCOMPAT attribute, - this Boolean value determines if the page is backward compatible. You must set this attribute to true if you are calling legacy ActiveX DLL's.

Server Controls

These controls are basically server side .NET components. The four types of server controls are HTML, ASP, Validation, and User. This article will not focus on the user control, it will be covered in a separate article later.

HTML Controls

These are your standard HTML controls with a few modifications that enable them to be used within ASP.NET. You can take any HTML control and add the ID and RUNAT attributes to make it a HTML server control.

<input type="text" id="txtName" runat="server" size="40">

ASP.NET Controls

A set of server-side components that can generate HTML or JavaScript for your ASP.NET pages. They also give developers the ability to program to events that are not available with HTML controls. This is one of the biggest improvements to ASP. Another advantage of ASP.NET controls is the ability to bind them to a data source, with includes XML recordsets.

<% @Page language="C#" %>
<html>
<body>
<script language="C#" runat="server">
 private void btnclick_click(object sender, EventArgs e)
 {
   lblresponse.Text = "You selected " + rgdemo.SelectedItem.Text;
 }
</script>
    <form runat=server>
        <asp:label id="lblMessage" text="Which do you prefer"
            runat="server" />
        <asp:RadioButtonList id="rgdemo" runat="server">
            <asp:ListItem selected="True">C##</asp:ListItem>
            <asp:ListItem>Visual Basic</asp:ListItem>
            <asp:ListItem>Delphi</asp:ListItem>
            <asp:ListItem>C++</asp:ListItem>
            <asp:ListItem>Other</asp:ListItem>
        </asp:RadioButtonList>
        <br><br>
        <asp:button id="btnclick" text="Click Here"
            onClick="btnclick_click" runat="server" />
        <br><br>
        <asp:label id="lblresponse" runat="server" />
    </form>
</body>
</html>

Validation Controls

Validation controls attach to input controls, they work together to provide developers with the ability to check required fields, patterns, ranges, and other routine validation scenarios.

<% @Page language="C#" %>
<html>
<body>
<form runat=server action="validate.aspx">
<TABLE>
 <TR>
  <TD>
   <asp:label id="lbltext" text="Type is a number greater than 10 "
     runat="server"/>
   <asp:Textbox id="txtnumber" runat="server" size="5" />
 </TD>
 <TD>
   <asp:CompareValidator id="valtext" runat="server"
     ForeColor="Red" ControlToValidate="txtnumber" Type="Integer"
     ValueToCompare=10 Operator="GreaterThanEqual"
     ErrorMessage="Please enter a number greater than 10!" />
</TD>
</TR>
</TABLE>
<asp:button type="submit" runat="server" id="btnsubmit"
  text="Validate Me!" />
</form>
</body>
</html>

Summary

This article gave you a brief overview of the new ASP.NET framework. We will expand on this article in the following weeks to cover fundamental areas of ASP.NET. If you have any comments or questions regarding this article, please feel free to send me an e-mail.

Related Links


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers