.NET Tips and Tricks

Blog archive

Don't Create Pages in SharePoint; Use User Controls

Because the Master Page for your SharePoint site is kept in the hive (and because Visual Studio isn't smart enough to follow the MasterPageFile attribute that points to the Master Page in the hive) when creating a page in Visual Studio, you can't switch to Design View. For those of you with a great grasp of HTML that may not be a problem. Because of my shaky grasp of HTML and CSS, when I work in Source View I'm frequently surprised at what shows up in the browser when I view my page.

There are workarounds for this problem (copying your site's Master Page into your project and setting/resetting your page's MasterPageFile to point to the local copy, for instance). Lately, however, I've been using a hint from my friend Patrick Haggerty (who wrote Learning Tree's SharePoint Development course). When I create a page, I don't add controls directly to the page. Instead, I create a User Control and add my controls to it. I then add my User Control to the appropriate Content control on the page I'm creating. When I'm creating a User Control, I always have both Design View (which I like) and Source View (when I need it). Until Visual Studio gets smarter (and Visual Studio 2012 hasn't), this is the best solution I've got.

Posted by Peter Vogel on 04/22/2013


comments powered by Disqus

Featured

Subscribe on YouTube