Back to Vlad
Project 4

ASP.NET Forms

Learn to write code in Web Forms: one button, one label, and a small family of classes that answer the same question differently.

Sklyarenko Vlad

Sklyarenko Vlad

01 · The task

Develop an application using a Web Form

The goal of the work is to learn to write code in Web Forms. These are the steps from the lecture. Tick them off as you go.

0 of 7 done

On this site the pair is named project-4-form.aspx and project-4-form.aspx.cs instead of Default.aspx, so it can sit next to the other projects.

02 · Try it

Press Start and watch the code run

This is a browser copy of the Web Form with the same logic. Pick which class goes into each seat of the family array, press Start, and follow the call from the button down to the label.

project-4-form.aspx

Project 4. ASP.NET OOP

03 · OOP

One parent, two children

APerson says a method can be changed (virtual). AMan and AWoman inherit from it (: APerson) and change it (override). The array is typed APerson[], yet each call runs the version of the real object. That is polymorphism. Change the selects above to see it.

04 · The real files

The ASP.NET page

Here is the markup and the code-behind. The label and the button are server controls (runat="server"), and OnClick connects the button to the C# method.

From a console program to a Web Form

The lecture shows the same program as a console application. Almost nothing changes, only the entry and the output.

Console programWeb Form
Where it startsMain()cmbStart_Click(), after a click
Methodsstaticinternal, of the page class
OutputConsole.Write(result)lblResult.Text = result
New line"\n\r""<br>"

Open the real page

This button opens project-4-form.aspx. It is processed by the server, so it needs both files on an ASP.NET host. On a plain file server, or when you open the files from your computer, it will not run.

Open the ASP.NET page
05 · Notes

Names and ideas

Hungarian notation

A short prefix tells you the kind of control, so cmbStart is obviously the Start button.

PrefixControlExample
lblLabellblResult
cmbButton (the name used in the lecture)cmbStart
txtTextBoxtxtName
chkCheckBoxchkAgree
ddlDropDownListddlCity
Web hosting by Somee.com