15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

asP.neT Web forms ❘ 1165<br />

For starters, create a new empty web site in Visual Studio .<strong>NET</strong> in the C:\ProCSharp\Chapter40\<br />

directory, <strong>and</strong> call it PCSWebSite2. Next, add a new Web Form using the default settings <strong>and</strong> modify the<br />

code in the generated Default.aspx file as follows:<br />

<br />

<br />

<br />

<br />

Meeting Room Booker<br />

<br />

<br />

<br />

<br />

<br />

Enter details <strong>and</strong> set a day to initiate an event.<br />

<br />

<br />

code snippet PCSWebSite2/Default.aspx<br />

After the title of the page (which is enclosed in HTML tags to get large, title-style text), the<br />

main body of the form is enclosed in an HTML . You could use a web server control table, but<br />

this introduces unnecessary complexity because you are using a table purely for formatting the display,<br />

not to be a dynamic UI element. This is an important point to bear in mind when designing Web<br />

Forms — don’t add web server controls unnecessarily. The table is divided into three columns: the first<br />

column holds simple text labels; the second column holds UI fields corresponding to the text labels<br />

(along with validation controls for these); <strong>and</strong> the third column contains a calendar control for date<br />

selection, which spans four rows. The fifth row contains a submission button spanning all columns,<br />

<strong>and</strong> the sixth row contains a ValidationSummary control to display error messages, when required<br />

(all the other validation controls have Display=“None”, because they will use this summary for display).<br />

Beneath the table is a simple label that you can use to display results for now, before you add database<br />

access later:<br />

<br />

<br />

<br />

<br />

Your Name:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Event Name:<br />

<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!