Marco Bellinaso's Blog

 Wednesday, March 29, 2006

After a long time of silence, starting with this entry I'm going to post on this blog a number of excerpts from my new book, "ASP.NET 2.0 Website Programming", soon to be found in all good book stores :-). Please note that these pieces are taken from the Design section of the chapters, that is where I introduce the new ASP.NET 2.0 features & controls, and use that background information to design the module covered by the chapter. It's in the Solution section that the real code is actually being written to implement the sample website, and it's that part that I believe is more interesting and useful for many developers. However, that section is not very good for taking self-containing excerpts, as it should be read as a whole, and therefore I had to chose some examples from the Design. Hope you appreciate them :-) As usual, any feedback is very welcome!


Enter the Master Page Model (Chapter 2)

ASP.NET 2.0 introduces a new “master page” feature that enables you to define common areas that every page will share, such as headers, footers, menus, and so on. A master page enables you to put the common layout code in a single file and have it visually inherited in all the content pages. A master page contains the overall layout for your site. Content pages can inherit the appearance of a master page, and place their own content where the master page has defined a ContentPlaceHolder control. Although this has the effect of providing a form of visual inheritance, it’s not really implemented with inheritance in an OOP sense—instead, the underlying implementation of master pages is based on a template model.

An example is worth a thousand words, so let’s see how this concept turns into practice. A master page has a .master extension and is similar to a user control under the covers. Following is some code for a master page that contains some text, a header, a footer, and defines a ContentPlaceHolder control between the two:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

 

<html>

<head id="Head1" runat="server">

   <title>TheBeerHouse</title>

</head>

 

<body>

<form id="Main" runat="server">

   <div id="header">The Beer House</div>

   <asp:ContentPlaceHolder ID="MainContent" runat="server" />

   <div id="footer">Copyright 2005 Marco Bellinaso</div>

</form>

</body>

</html>

As you see, it is extremely similar to a standard page, except that it has a @Master directive at the top of the page instead of a @Page directive, and it declares one or more ContentPlaceHolder controls where the .aspx pages will add their own content. The master page and the content page will merge together at runtime—therefore, because the master page defines the <html>, <head>, <body> and <form> tags, you can easily guess that the content pages must not define them again. Content pages will only define the content for the master’s ContentPlaceHolder controls, and nothing else. The following extract shows an example of a content page:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="MyPage.aspx.cs" Inherits="MyPage" Title="The Beer House - My Page" %>

 

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" Runat="Server">

   My page content goes here...

</asp:Content>

The first key point is that the @Page directive sets the MasterPageFile attribute to the virtual path of the master page to use. The content is placed into Content controls whose ContentPlaceHolderID must match the ID of one of the ContentPlaceHolder controls of the master page. In a content page, you can’t place anything but Content controls, and other ASP controls that actually define the visual features must be grouped under the outermost Content controls. Another point to note is that the @Page directive has a new attribute, Title, that allows you to override the value specified in the master page’s <title> metatag. If you fail to specify a Title attribute for a given content page, then the title specified on the master page will be used instead.

Figure 2-2 provides a graphical representation of the master page feature.

Figure 2-2

When you edit a content page in Visual Studio, it properly renders both the master page and the content page in the form designer, but the master page content appears to be “grayed out.” This is done on purpose as a reminder to you that you can’t modify the content provided by the master page when you’re editing a content page.

I’d like to point out that your master page also has a code-beside file that could be used to write some C# properties and functions that could be accessed in the .aspx or code-beside files of content pages.

When you define the ContentPlaceHolder in a master page, you can also specify the default content for it, which will be used in the event that a particular content page doesn’t have a Content control for that ContentPlaceHolder. Here is a snippet that shows how to provide some default content:

<asp:ContentPlaceHolder ID="MainContent" runat="server">

   The default content goes here…

</asp:ContentPlaceHolder>

Default content is helpful to handle situations in which you want to add a new section to a number of content pages, but you can’t change them all at once. You can set up a new ContentPlaceHolder in the master page, give it some default content, and then take your time in adding the new information to the content pages—the content pages that haven’t been modified yet will simply show the default content provided by the master.

The MasterPageFile attribute at the page level may be useful if you want to use different master pages for different sets of content pages. If, however, all pages of the site use the same master page, it’s easier to set it once for all pages from the web.config file, by means of the <pages> element, as shown here:

<pages masterPageFile="~/Template.master" />

If you still specify the MasterPageFile attribute at the page level however, that attribute will override the value in web.config for that single page.



NOTE: This excerpt was taken from the book "ASP.NET 2.0 Website Programming". Click here to find more about it, and download the complete source code of the sample project.

9/20/2008 3:26:32 PM (GMT Daylight Time, UTC+01:00)
World of Warcraft Gold is very need for everyone!
10/31/2008 12:51:45 AM (GMT Standard Time, UTC+00:00)
[url=http://www.thepowerlevel.com]wow gold[/url]
[url=http://www.thepowerlevel.com/Gold.php?N=WOW_EU]cheap wow gold[/url]
[url=http://www.thepowerlevel.com/Powerleveling.php?N=WOW_US]wow power leveling[/url]

[url=http://www.thepowerlevel.com/Gold.php?N=AOC_US]age of conan gold[/url]
[url=http://www.thepowerlevel.com/Gold.php?N=Runescape]runescape gold[/url]
[url=http://www.thepowerlevel.com/Gold.php?N=MapleStory]maplestory mesos[/url]
12/25/2008 8:08:29 AM (GMT Standard Time, UTC+00:00)
[url=http://www.myrsmoney.com/]runescape money[/url]
[url=http://www.myrsmoney.com/]runescape gold[/url]
[url=http://www.myrsmoney.com/runescape-powerleveling.html]runescape power leveling[/url]
[url=http://www.myrsmoney.com/runescape-powerleveling.html]cheap runescape power leveling[/url]
[url=http://www.myrsmoney.com/runescape-powerleveling.html]rs powerleveling[/url]
[url=http://www.myrsmoney.com/runescape-accounts.html]runescape accounts[/url]
[url=http://www.myrsmoney.com/runescape-accounts.html]buy cheap runescape accounts[/url]
[url=http://www.myrsmoney.com/runescape-accounts.html]cheapest runescape accounts[/url]
[url=http://www.myrsmoney.com/runescape-accounts.html]rs accounts[/url]
[url=http://www.myrsmoney.com/runescape-gold-farming.html]runescape gold farming[/url]
[url=http://www.myrsmoney.com/runescape-items.html]runescape items[/url]
[url=http://www.rs2happy.com/runescape-gold]runescape gold[/url]
[url=http://www.rs2happy.com/runescape-gold]cheap runescape gold[/url]
[url=http://www.rs2happy.com/runescape-gold]buy runescape gold[/url]
[url=http://www.rs2happy.com/runescape-money]runescape money[/url]
[url=http://www.rs2happy.com/runescape-money]cheap runescape money[/url]
[url=http://www.rs2happy.com/runescape-money]buy runescape money[/url]
[url=http://www.rs2happy.com/runescape-accounts]runescape accounts[/url]
[url=http://www.rs2happy.com/runescape-accounts]cheap runescape accounts[/url]
[url=http://www.rs2happy.com/runescape-accounts]buy runescape accounts[/url]
[url=http://www.rs2happy.com/runescape-powerleveling]runescape power leveling[/url]
[url=http://www.rs2happy.com/runescape-powerleveling]runescape powerleveling[/url]
[url=http://www.rs2happy.com/runescape-powerleveling]cheap runescape power leveling[/url]
[url=http://www.rs2happy.com/runescape-gold-farming]runescape gold farming[/url]
[url=http://www.rs2happy.com/runescape-items]runescape items[/url]
[url=http://www.rs2seller.com/runescape-gold]runescape gold[/url]
[url=http://www.rs2seller.com/runescape-gold]cheap runescape gold[/url]
[url=http://www.rs2seller.com/runescape-gold]buy runescape gold[/url]
[url=http://www.rs2seller.com/runescape-money]runescape money[/url]
[url=http://www.rs2seller.com/runescape-money]cheap runescape money[/url]
[url=http://www.rs2seller.com/runescape-money]buy runescape money[/url]
[url=http://www.rs2seller.com/runescape-accounts]runescape accounts[/url]
[url=http://www.rs2seller.com/runescape-accounts]cheap runescape accounts[/url]
[url=http://www.rs2seller.com/runescape-accounts]buy runescape accounts[/url]
[url=http://www.rs2seller.com/runescape-powerleveling]runescape power leveling[/url]
[url=http://www.rs2seller.com/runescape-powerleveling]runescape powerleveling[/url]
[url=http://www.rs2seller.com/runescape-powerleveling]cheap runescape power leveling[/url]
[url=http://www.rs2seller.com/runescape-gold-farming]runescape gold farming[/url]
[url=http://www.rs2seller.com/runescape-items]runescape items[/url]
[url=http://www.rs2net.com/runescape-gold]runescape gold[/url]
[url=http://www.rs2net.com/runescape-gold]cheap runescape gold[/url]
[url=http://www.rs2net.com/runescape-gold]buy runescape gold[/url]
[url=http://www.rs2net.com/runescape-money]runescape money[/url]
[url=http://www.rs2net.com/runescape-money]cheap runescape money[/url]
[url=http://www.rs2net.com/runescape-money]buy runescape money[/url]
[url=http://www.rs2net.com/runescape-accounts]runescape accounts[/url]
[url=http://www.rs2net.com/runescape-accounts]cheap runescape accounts[/url]
[url=http://www.rs2net.com/runescape-accounts]buy runescape accounts[/url]
[url=http://www.rs2net.com/runescape-powerleveling]runescape power leveling[/url]
[url=http://www.rs2net.com/runescape-powerleveling]runescape powerleveling[/url]
[url=http://www.rs2net.com/runescape-powerleveling]cheap runescape power leveling[/url]
[url=http://www.rs2net.com/runescape-gold-farming]runescape gold farming[/url]
[url=http://www.rs2net.com/runescape-items]runescape items[/url]
2/27/2009 8:49:04 AM (GMT Standard Time, UTC+00:00)
http://www.vghp.com
http://www.vghp.com/runescape_en.html
http://www.vghp.com/runescape_en.html
http://www.vghp.com/runescape_en.html
http://www.vghp.com/runescape_en.html
http://www.vghp.com/finalfantasyxi_en.html
http://www.vghp.com/finalfantasyxi_en.html
http://www.vghp.com/finalfantasyxi_en.html
http://www.vghp.com/finalfantasyxi_en.html
http://www.vghp.com/tibia-gold.html
http://www.vghp.com/guildwars_en.html
http://www.vghp.com/guildwars_en.html
http://www.vghp.com/guildwars_en.html
http://www.vghp.com/dofus-kamas.html
http://www.vghp.com/dofus-kamas.html
http://www.vghp.com/powerleveling.html

http://www.sgw.mobi
http://www.sgw.mobi/subsgw/dofus.html
http://www.sgw.mobi/subsgw/ff11.html
http://www.sgw.mobi/subsgw/gaia.html
http://www.sgw.mobi/subsgw/gw.html
http://www.sgw.mobi/subsgw/rs.html
http://www.sgw.mobi/subsgw/powerleveling-runescape.html

http://www.ffxi-gil.us

http://www.rs2server.com
4/15/2009 9:14:23 AM (GMT Daylight Time, UTC+01:00)
I like a game which needs to use [url=http://www.virgame.com/pristontale-c-131.html]priston tale Gold[/url], when you do not have [url=http://www.virgame.com/pristontale-c-131.html]priston tale Money [/url], you must borrow it from friends, or you[url=http://www.virgame.com/pristontale-c-131.html]buy priston tale Gold[/url]. If you get [url=http://www.virgame.com/pristontale-c-131.html]cheap priston tale Gold[/url], you can continue this game.
4/17/2009 2:37:50 AM (GMT Daylight Time, UTC+01:00)
[url=http://www.uppowerleveling.com]wow power leveling[/url][url=http://www.uppowerleveling.com]wow powerleveling[/url][url=http://www.uppowerleveling.com]powerleveling[/url][url=http://www.uppowerleveling.com]power leveling[/url][url=http://www.uppowerleveling.com]wow gold[/url][url=http://www.uppowerleveling.com]powerleveling[/url][url=http://www.uppowerleveling.com]World of Warcraft power leveling[/url][url=http://www.up-powerleveling.com]wow power leveling[/url][url=http://www.up-powerleveling.com]wow powerleveling[/url][url=http://www.up-powerleveling.com]powerleveling[/url][url=http://www.up-powerleveling.com]power leveling[/url] [url=http://www.up-powerleveling.com]wow gold[/url][url=http://www.up-powerleveling.com]powerleveling[/url][url=http://www.up-powerleveling.com]World of Warcraft power leveling[/url] [url=http://www.uppowerleveling.com]aion power leveling[/url] [url=http://www.uppowerleveling.com]aion powerleveling[/url]
4/29/2009 2:12:19 PM (GMT Daylight Time, UTC+01:00)
[url=http://www.gold4key.com]Sell WoW Gold[/url]
[url=http://www.gold4key.com]Trade WOW Gold<[/url]
[url=http://www.gold4key.com]Buy cd keys online[/url]
[url=http://www.gold4key.com]Sell World of Warcraft gold[/url]
[url=http://www.goldsales4u.com]buy wow gold[/url]
[url=http://www.goldsales4u.com]buy cheap wow gold[/url]
[url=http://www.goldsales4u.com]buy wow gold cheap[/url]
[url=http://www.goldsales4u.com]buy lotro gold[/url]
6/11/2009 3:57:22 AM (GMT Daylight Time, UTC+01:00)
Although the game is free to play, we have to cost some shaiya money to buy our favorite equipment.
6/11/2009 7:55:10 AM (GMT Daylight Time, UTC+01:00)
you can also borrow gold from other players
6/18/2009 2:05:32 AM (GMT Daylight Time, UTC+01:00)
wakfu kamas that you have to remember that it may perhaps be a boring method of playing the game but this will surely provide you enough experience for the game.
6/18/2009 2:48:04 AM (GMT Daylight Time, UTC+01:00)
It is really what I want to find out, very useful.
6/18/2009 4:52:43 AM (GMT Daylight Time, UTC+01:00)
good
6/18/2009 5:27:24 AM (GMT Daylight Time, UTC+01:00)

Do you like the gold?
6/18/2009 7:17:24 AM (GMT Daylight Time, UTC+01:00)
good site
6/18/2009 8:17:29 AM (GMT Daylight Time, UTC+01:00)
Do you know Darkfall Gold? I like it.
6/18/2009 8:22:50 AM (GMT Daylight Time, UTC+01:00)
latale online gold in the game which movement is much like an arcade game where you can drop down to the lower area.
6/18/2009 9:38:09 AM (GMT Daylight Time, UTC+01:00)
YOU can come here to buy the cheapest gold
6/18/2009 10:22:13 AM (GMT Daylight Time, UTC+01:00)
It is good.
6/23/2009 7:56:00 AM (GMT Daylight Time, UTC+01:00)
http://www.flooring-China.com
ldp
8/5/2009 1:06:14 PM (GMT Daylight Time, UTC+01:00)
Ugg is a big brand which is famous for its fashion products and good quality. The products consist of[url=http://www.oursugg.com/ugg-nightfall-c-47.html]Ugg Nightfall[/url]
, [url=http://www.oursugg.com/ugg-classic-mini-c-51.html]Ugg Classic Mini[/url], [url=http://www.oursugg.com/ugg-sunburst-tall-c-48.html]Ugg Sunburst Tall[/url], [url=http://www.oursugg.com/ugg-classic-cardy-c-49.html]Classic Cardy[/url]
, [url=http://www.oursugg.com/ugg-classic-short-c-54.html]Short Classic Uggs[/url], [url=http://www.oursugg.com/ugg-lo-pro-classic-tall-c-46.html]Ugg Classic Tall[/url]
, [url=http://www.oursugg.com/ugg-classic-crochet-c-53.html]Classic Crochet[/url].
You can feel UGG Australia luxury when you slip into this[url=http://www.oursugg.com/ugg-classic-cardy-c-49.html]women's classic cardy[/url] boot.Its precision craftsmanship is evident in the reinforced heel and raw seams. The [url=http://www.oursugg.com/ugg-classic-short-c-54.html]Classic Short boots
[/url] feature lavish twin-faced sheepskin for the utmost comfort. Precision craftsmanship is evident in the Classic Short's reinforced heel and raw seams. Look at [url=http://www.oursugg.com/ugg-classic-mini-c-51.html]Ugg Classic Mini boots[/url], buy one and have a try, you will understand its charm. These chestnut boots offer everything you need in casual, cold-weather footwear.
Young ladies always pursuit popular and personality. Pay attention to this rum raisin [url=http://www.oursugg.com/ugg-classic-crochet-c-53.html]Ugg Women's Classic Crochet boot[/url], you will find it is so distinctive. It is made of woven wool, and looks simple and casual. Design of woven wool makes this gray [url=http://www.oursugg.com/ugg-classic-cardy-c-49.html]women's classic cardy[/url] looks both beautiful and comfortable to wear on the feet. Knitting wool, allow your feet to breathe easily.

8/5/2009 2:07:18 PM (GMT Daylight Time, UTC+01:00)
Beautiful ladies and girls,look here [url=http://www.100mfugg.com/] www.100mfugg.com [/url] , you will find beautifull and cheap ugg boots.
Such as:
[url=http://www.100mfugg.com/ugg-classic-cardy-c-2.html]Classic Cardy boots [/url]
[url=http://www.100mfugg.com/ugg-classic-tall-c-3.html]women’s classic tall [/url]
[url=http://www.100mfugg.com/ugg-sundance-c-7.html]UGG Sundance II [/url]
[url=http://www.100mfugg.com/ugg-ultra-short-c-8.html] Short ugg Ultra [/url]
and so on.
I promise you'll fall in love as soon as you slip these on.
8/10/2009 1:39:35 PM (GMT Daylight Time, UTC+01:00)
UGG have been popular to star in Hollywood for several years.
[url=http://www.uggur.com]UGG[/url] is not a brand name but an age old generic term for this style of Australian-made sheepskin boot. [url=http://www.uggur.com]ugg cardy[/url] is made of special materials - plush fleece. In cold weather, the plush fleece provides an insulating layer of warmth by trapping your body heat, much like goose down does. But in the heat of summer, the natural fibers of the fleece actually cool your feet by wicking away perspiration. So [url=http://www.uggur.com]ugg classic[/url] Boots are suitable for people of all ages.

birthday present

I can get [url=http://www.uggur.com]ugg cardy[/url] cheaply, Yesterday i bought
[url=http://www.uggur.com]UGG[/url] boots online kina for my sister. i hope she like it. i will give [url=http://www.uggur.com/ugg-classic-cardy-c-58.html]UGG Classic Cardy[/url] to her as birthday present. i like the cheap [url=http://www.uggur.com/ugg-classic-crochet-c-61.html]UGG Classic Crochet[/url] very much. I usually buy [url=http://www.uggur.com/ugg-classic-mini-c-60.html]UGG Classic Mini[/url] and keep [url=http://www.uggur.com/ugg-classic-short-c-57.html]UGG Classic Short[/url] in my store. I can get [url=http://www.uggur.com/ugg-classic-tall-c-59.html]UGG Classic Tall[/url] cheaply, i bought [url=http://www.uggur.com/ugg-gypsy-sandal-c-69.html]Ugg Gypsy Sandal[/url] online kinafor my brother last year . i hope him like [url=http://www.uggur.com/ugg-halendi-sandal-c-68.html]Ugg Halendi Sandal[/url]. i will give [url=http://www.uggur.com/ugg-sundance-c-63.html]UGG Sundance[/url] to him as birthday present. i like the cheap [url=http://www.uggur.com/ugg-tasmina-c-66.html]Ugg Tasmina[/url] very much. I usually buy [url=http://www.uggur.com]UGG Sale[/url] and keep it in my store.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

 
Get RSS/Atom Feed
RSS 2.0 | Atom 1.0
Search in the blog
Archive
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
Categories

Powered by: newtelligence dasBlog 1.8.5223.1