Working with Types


As with every chapter, we start with setting up the sample application that will let you put the concepts in this chapter into practice. Of course, it's always our desire in this book to have you try out things that are practical and give you a feel for the real world, but that gets old fast. For this chapter you're going to do something different. You'll see that throughout this chapter there is a superhero theme, so it seems fitting to create a Web site that lets you offer feedback to your favorite superheroes. In this Web site superheroes will be able to register themselves as servants of humanity and describe their super powers. People will then come to the site when they are in need of superhero action, and can request a superhero to do a particular job. Then, people can rank the superhero in a scale of 1 to 5 as to how well he or she performed the task. What does this have to do with learning about types, you may ask? Well, there's a lot of database work in this Web site, and a number of database operations require you to do type comparisons and conversions. Other than that, it's just a lot of fun.

There's one more thing to discuss regarding the sample application for this chapter. To make the application fully functional, you have to add various pieces of code to four different formsthat's a little too much for this chapter. Rather, we're going to focus on making one of the forms functional. You can download the rest of the code from Peachpit's Web site. You'll find the download link in the Tips later in this section.

To create a test project for this chapter:

  1. Launch Visual Studio .NET. (Start > All Programs > Microsoft Visual Studio .NET > Microsoft Visual Studio .NET).

  2. Select File > New > Project to bring up the New Project dialog.

  3. Under project types on the left side of the New Project window click the Visual C# projects folder.

  4. Select the ASP.NET Web Application icon and change the name of the application to typesproject ( Figure 7.1 ).

    Figure 7.1. Here's the New Project dialog that you've grown to love.

    graphics/07fig01.gif

  5. Visual Studio will create a new project and open WebForm1.aspx.

  6. Change the form's name to mainmenu .aspx. Do so by choosing View > Solution Explorer from the top menu bar.

  7. Right-click on WebForm1.aspx and choose properties. In the property grid below, change the FileName property from WebForm1.aspx to mainmenu.aspx ( Figure 7.2 ).

    Figure 7.2. The Properties window enables you to set the page's filename if you click on the page first in the Solution Explorer.

    graphics/07fig02.gif

  8. Add four other forms to your project. Do so by selecting Project > Add Web Form. You'll see the dialog in Figure 7.3 . Name the first register.aspx, the second helprequest.aspx, the third schedule.aspx and the fourth feedback.aspx.

    Figure 7.3. This project has five Web forms total. In the chapter you'll focus on getting the feedback.aspx form working.

    graphics/07fig03.gif

  9. Change the main menu form so that it looks like the form in Figure 7.4 . Obviously this is a lot of work to do by hand. Instead you can enter the HTML directly into the editor. Figure 7.5 on the next page shows the HTML necessary to create the form. To enter the HTML directly, click the HTML button under the editor's window. As an alternative you could download the skeleton file for this project (see Tips on the next page).

    Figure 7.4. The main form serves as the main menu for the application. It consists of a label and three links. The links are instances of the Hyperlink control.

    graphics/07fig04.gif

    Figure 7.5 Use the HTML in this figure as a reference in case you're trying to write the form from scratch.
     <%@ Page language="c#" Codebehind="mainmenu.aspx.cs"          AutoEventWireup="false"          Inherits="typesproject.WebForm1"          enableViewState="False"          enableViewStateMac="False"%> <HTML>    <HEAD>       <title>WebForm1</title>    </HEAD>    <body MS_POSITIONING="GridLayout">       <form id="Form1" method="post"       runat="server">         <asp:  Label  id="lblTitle"            style="Z-INDEX: 101;            LEFT: 20px;            POSITION: absolute;            TOP: 20px"            runat="server"            Font-Size="X-Large">  Welcome to Superheroes for Hire!  </asp:Label>         <asp:  HyperLink  id="lnkRegister"            style="Z-INDEX: 102;            LEFT: 20px;            POSITION: absolute;            TOP: 76px"            runat="server"            NavigateUrl="register.aspx">  Register  </asp:HyperLink>         <asp:  HyperLink  id="lnkFeedback"            style="Z-INDEX: 103;            LEFT: 20px;            POSITION: absolute;            TOP: 133px"            runat="server"            NavigateUrl="feedback.aspx">  Feedback  </asp:HyperLink>         <asp:  HyperLink  id="HyperLink1"           style="Z-INDEX: 104;           LEFT: 20px;           POSITION: absolute;           TOP: 103px"           runat="server"         NavigateUrl="helprequest.aspx">  I need help!!!  </asp:HyperLink>       </form>    </body> </HTML> 

graphics/tick.gif Tips

  • In this chapter we'll focus on making the feedback form, feedback.aspx, fully functional.

  • Remember that like any other project in this book, building the project isn't necessary for learning the concepts in this chapter.

  • Skeletons for each project can be downloaded from Peachpit's Web site, http://www.peachpit.com/vqs/csharp.




C#
C# & VB.NET Conversion Pocket Reference
ISBN: 0596003196
EAN: 2147483647
Year: 2003
Pages: 198
Authors: Jose Mojica

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net