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:
1: <%@ Master Language="C#" %>
3: <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=188.8.131.52, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
4: <%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=184.108.40.206, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
5: <%@ Import Namespace="Microsoft.SharePoint" %>
6: <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
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:
1: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
Is actually totally useless because the .dtd it references is a on path relative to w3c’s website! Use this instead:
1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
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:
1: <@ Register tagprefix=”Mcs”, tagName=”OrderWidget”, src=”~/OrderWidgetControl.ascx” %>
1: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5: <head runat="server">
6: <title>Order Page</title>
9: <form id="form1" runat="server">
10: <Mcs:OrderWidget runat="server" />
In SharePoint's default.master, this is used extensively. Here is an example:
1: <%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=220.127.116.11, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
And further down:
1: <WebPartPages:SPWebPartManager ID="m" runat="Server" />
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:
1: <html dir="<%$Resources:wss,multipages_direction_dir_value%>" runat="server" xmlns:o="urn:schemas-microsoft-com:office:office">
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:
1: <data name="multipages_direction_dir_value">
Pretty nifty! More later…