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 ❘ 1159<br />

This time, the value of the view state contains more information because the HTML result relies on more<br />

than the default output from the ASP.<strong>NET</strong> page. In complex forms this can be a very long string indeed,<br />

but you shouldn ’ t complain because so much is done for you behind the scenes. You can almost forget about<br />

state management, keeping fi eld values between posts, <strong>and</strong> so on. Where the length of the view state string<br />

becomes a problem, you can disable the view state for controls that do not need to retain state information.<br />

You can also do this for entire pages if you want, which can be useful if the page does not ever need to<br />

retain state between postbacks to improve performance.<br />

For more on view state, see Chapter 41.<br />

To convince yourself that you don ’ t need to perform any compilation for web sites manually, try changing<br />

the text “ Button clicked! ” in Default.aspx.cs to something else, saving the fi le, <strong>and</strong> clicking the button<br />

again. The text on the web page should change appropriately.<br />

The Control Palette<br />

This section takes a quick look at some of the available controls before you put more of them together into<br />

a full, <strong>and</strong> more interesting, application. Figure 40 - 6 shows the toolbox that you see<br />

when editing ASP.<strong>NET</strong> pages.<br />

Note that the following control descriptions discuss properties; in all cases, the<br />

corresponding attribute for use in ASP.<strong>NET</strong> code is identically named. This section<br />

isn ’ t an attempt to provide a complete reference, so instead, we focus on only the<br />

most frequently used controls <strong>and</strong> properties. The controls you see in this chapter<br />

are in the St<strong>and</strong>ard, Data, <strong>and</strong> Validation categories. The Navigation, Login, Web<br />

Parts, <strong>and</strong> AJAX Extensions categories are covered in Chapter 41. The Reporting<br />

controls to be presented on web pages, which enable reporting information,<br />

including Crystal Reports, are not covered in this book.<br />

St<strong>and</strong>ard Web Server Controls<br />

figure 40-6<br />

Almost all the web server controls (in this <strong>and</strong> other categories) inherit from<br />

System.Web.UI.WebControls.WebControl , which in turn inherits from System.Web.UI.Control .<br />

Those that don ’ t use this inheritance instead derive either directly from Control or from a more specialized<br />

base class that derives (eventually) from Control . As a result, the web server controls have many common<br />

properties <strong>and</strong> events that you can use as required. There are quite a few of these, so we won ’ t attempt to<br />

cover them all, just as with the properties <strong>and</strong> events of the web server controls themselves.<br />

Many of the frequently used inherited properties are those that deal with display style. This can be<br />

controlled simply, using properties such as ForeColor , BackColor , Font , <strong>and</strong> so on, but can also<br />

be controlled using CSS classes. To use CSS styling, you set the string property CssClass to the name of<br />

a CSS class in a separate fi le. You can use the CSS Properties window along with the style management<br />

windows to assist you with CSS control styling. Other notable properties include Width <strong>and</strong> Height to<br />

size a control, AccessKey <strong>and</strong> TabIndex to ease user interaction, <strong>and</strong> Enabled to set whether the control ’ s<br />

functionality is activated in the Web Form.<br />

Some controls can contain other controls, building up a control hierarchy on a page. You can get access to<br />

the controls contained by a given control using its Controls property, or to the container of a control via<br />

the Parent property.<br />

You are likely to use the inherited Load event most often, to perform initialization on a control, <strong>and</strong><br />

PreRender to perform last - minute modifi cations before HTML is output by the control.<br />

Plenty more events <strong>and</strong> properties exist, <strong>and</strong> you see many of these in more detail in the next chapter. In<br />

particular, Chapter 41 deals with more advanced styling <strong>and</strong> skinning techniques. The following table<br />

describes the st<strong>and</strong>ard web server controls in more detail.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!