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.

1210 ❘ ChaPTer 41 Asp.net feAtures<br />

Page.Theme = Session["SessionTheme"] as string;<br />

}<br />

else<br />

{<br />

Page.Theme = "DefaultTheme";<br />

}<br />

}<br />

}<br />

// base call<br />

base.OnPreInit(e);<br />

code snippet PCSDemoSite/App_Code/MyPageBase.cs<br />

This event h<strong>and</strong>ler checks the session state for an entry in SessionTheme <strong>and</strong> applies the selected theme if<br />

there is one; otherwise DefaultTheme is used.<br />

Note also that this class inherits from the usual page base class Page. This is necessary because, otherwise,<br />

the page wouldn’t function as an ASP.<strong>NET</strong> web page.<br />

For this to work, it is also necessary to specify this base class for all web pages. There are several ways of<br />

doing this, the most obvious being either in the directive for a page or in the code behind a<br />

page. The former strategy is fine for simple pages but precludes the use of custom code behind for a page, as<br />

the page will no longer use the code in its own code-behind file. The other alternative is to change the class<br />

that the page inherits from in the code-behind file. By default, new pages inherit from Page, but you can<br />

change this. In the code-behind file for the theme selection page shown earlier, you may have noticed the<br />

following code:<br />

public partial class _Default : MyPageBase<br />

{<br />

...<br />

}<br />

code snippet PCSDemoSite/Configuration/Themes/Default.aspx.cs<br />

Here MyPageBase is specified as the base of the Default class, <strong>and</strong> thus the method override in<br />

MyPageBase.cs is used.<br />

Web ParTs<br />

ASP.<strong>NET</strong> contains a group of server controls known as Web Parts, which are designed to enable users to<br />

personalize web pages. You may have seen this in action, for example, in SharePoint-based web sites or on<br />

the My MSN home page: http://my.msn.com/. When you use Web Parts, the resulting functionality is<br />

as follows:<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

Users are presented with a default page layout that you supply. This layout consists of a number of<br />

component Web Parts, each of which has a title <strong>and</strong> content.<br />

Users can change the position of the Web Parts on a page.<br />

Users can customize the appearance of Web Parts on a page or remove them from the page completely.<br />

Users can be supplied with a catalog of Web Parts that they can add to the page.<br />

Users can export Web Parts from a page, <strong>and</strong> then import them on a different page or site.<br />

Connections can exist between Web Parts. For example, the content displayed in a Web Part could be<br />

a graphical representation of the content displayed in another Web Part.<br />

Any changes that users make persist between site visits.<br />

ASP.<strong>NET</strong> supplies a complete framework for implanting Web Parts functionality, including management<br />

<strong>and</strong> editing controls.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!