I just ordered Inside Microsoft Windows SharePoint Services, by Ted Pattison and Daniel Larson. Two chapters are available online, which I came across while trying to understand how SharePoint uses master pages. The book recommends opening C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL\default.master and learning about now it works. In fact, this is the quote from the book “It's definitely worth your time to open up a copy of the default.master file within Microsoft Visual Studio and try to absorb all that's there.”
Okay, well, I am down for that.
The first few lines of the master page look like this:
The first line’s purpose is apparent, but what does <% @Register…%> mean? Here is where my ignorance comes into play. I did a ton of web development back in the Classic ASP days so the old <% %> tags look agonizingly familiar. Surely not the same thing, right?
No, but the family tree is apparent. Oh, by the way, as I read about ASP.NET Page Syntax, I branched off to learn something about DOCTYPES (great article). It is interesting to note the effect DOCTYPE has on how a browser renders a page and how validation is also effected. In particular, the DOCTYPE commonly cut and pasted from w3c’s web site:
Is actually totally useless because the .dtd it references is a on path relative to w3c’s website! Use this instead:
So, back to <% @Register…%>. The <% %> signals to ASP.NET that it should pay attention to the enclosed text. That’s about as simple as I can describe it.
When you use a control, such as a panel control, you use the syntax <asp:panel> </asp:panel>.
<% @Register…%> allows the developer to associate an alias with namespaces and classes so that you can essentially replicate the <asp:?> </asp:?> declaration but with custom user controls. So, if I have a control called OrderWidget, which collects order information on a page, I can use <% @Register…%> to create an alias to the OrderWidget control and declaratively include the control in my page:
In SharePoint's default.master, this is used extensively. Here is an example:
And further down:
A key difference from my simple example is the use of an AssemblyName, which relates the prefix to an assembly versus as .ascx file.
Default.master’s opening html tag looks like this:
The “dir” attribute indicates to the browser which direction text should run, which is important because many languages run right to left, versus English’s left to right.
Note the <%Resources:wss, multipages …%>. The <%$Resources…%> declaration is interesting. ASP.NET expressions (prefixed by the $ sign) is a powerful technology which enables the declarative setting of properties based on information evaluated at run time. In this case, the $Resources expression allows the loading of string resource information from a .resx file. In the example above, a wss.resx exists (which can be found in the 12 hive at C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG\Resources), which has a resource “multipages_direction_dir_value” defined:
Pretty nifty! More later…