Creating a Footer with a User Control

My goal was to add a simple footer area to the masterpage, with copyright year and a feedback link-simple stuff. I wanted it so that if the link or the date had to be changed, I wouldn’t have to update every instance of the masterpage. My brain still approaches Sharepoint with Dreamweaver mentalities. I am used to templates and library items in DW and how they work. Equating a masterpage to a DW template is faulty because it is no easy task to make a change to the masterpage and just hit “update” and ta da, the whole site is updated. When you make a change on the master page, you have to go into each site and subsite that uses the masterpage, change the masterpage to something else, and then change it back to have the updates show. For a large intranet, that is just not feasible.

Our old intranet uses Cold Fusion, and we use includes to pull in frequently changing text. I asked one of our .net guys is their was a .net version of this and he suggested user controls.

I opened my site in Sharepoint Designer and went to File > New, then clicked on the Page tab, ASP.NET, and selected Web User Control.

A base file will display. I removed the head content that automatically referenced the theme-it is unnecessary and caused problems with the rendering. I then pasted the html code for my footer. The css references were added to my theme file so that they would be picked up.

The first mistake I made was saving the user control within the site. That doesn’t work. I did some research and found out that user controls must be saved in the Controltemplates folder in the 12 hive on the server. Your path would be something like this:
\\server name\12$\TEMPLATE\CONTROLTEMPLATES

Now you have to add the user control to the masterpage and register it within the page. Find where you want to add the user control and add this code, where mp_footer = name of YOUR user control:

To register the user control, go to the top of your masterpage. There will be several user controls already listed there. Add this code after the other user control registration lines:

Save the masterpage, check it in, and then, yes, you must do the switch masterpage, switch back thing, but just this once 😉

Pretty easy and updating the user control automatically updates every instance throughout your masterpages, so I’m sure you can imagine the many ways you can use these in your sites. One tip about editing the user controls once they are on the server-open them in Notepad. I opened them in Designer and had trouble saving them back to the server. Enjoy 😉

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s