An Aspnet Web Page

You can migrate code from a console application to an ASP.NET Web Page. The coding is very similar, but you need to adjust code that deals with the user interface. With the console application, your user interface is the command line. With the ASP.NeT Web page, your user interface is a Web browser.

You can reuse many parts of the console application. In fact, except for the code pertaining to the user interface, much of the code will remain the same. The process for converting the console application is to create a user interface in HTML that gathers appropriate information. For example, you will use a drop-down list box in this task to prompt the user for the type of format in which they would like to see the date.

Console applications are closer to a procedural style of programming. The user interface is very simple, and users do not have many ways to interact with the program, except for command-line parameters. Moving from console applications to ASP.NET applications, you will need to understand how to use event handlers. To learn more about event handlers, see page 32.

CONVERT A CONSOLE APPLICATION TO AN ASP.NET WEB PAGE

S Untitled - Notepad

File Edit Format Help

^jsjjs]

(SCRIPT LANGUAGE-'C#" RUNAT="Server"s void SubmitBtn_Ciick(object Source, EventArgs e) {

spanMessaqe.innerHtml=GetFormattedDate(selectSugqesti oris. Value);

«H3>Convert to Web Paqe«/H3> «FORM ID="formConvert" RUNAT="Server">

cp/i

«SELECT ID-'selectSugqestions" RUNAT-'Server"?

«OPTION VALUE-'0">Short Date</OPTION> «OPTION VALUE-T'-Short Time</0PTI0N> «OPTION VALUE-'2"-Day of the Week«/OPTION=-«OPTION VALUE-'3">Date and Time«/OPTION> «/SELECT;-

«INPUT TYPE-'Submit" VALUE-Submit" OnServerCiick-'SubmitBtn_Click" RUNAT-'Serve r">

D Open the ConvertToWebPage Template.aspx template file from the CD-ROM.

'—0 Open the console application source file, DeclareUseMethods.cs, from the CD-ROM.

< Copy the GetFormattedDate function from

DeclareUseMethods.cs source file.

'—0 Open the console application source file, DeclareUseMethods.cs, from the CD-ROM.

< Copy the GetFormattedDate function from

DeclareUseMethods.cs source file.

Was this article helpful?

0 0

Post a comment