Skip to main content

Cloud

Smart Parts for the Smart Developer

Smart is what smart does.

If you have been following my recent blogs then you know the theme is to get an ASP.Net developer up and running with webpart development. In this blog I hope to show you what I document my methodology which should be very familiar to bread and butter ASP.Net developers.

One of the biggest drawbacks to the traditional webpart development I discussed previously has been the fact that there is no GUI designer available. Wouldn’t it be great to be able to design and develop custom User Controls with using the Visual Studio IDE?

Yes it would is the correct answer.

There is a caveat however. You must have control over the SharePoint server in order to setup a folder or two for your .ascx and code behind files which is kinda required for webpart installation anyway.

SmartPart:

This is the term given to a reusable webpart that can be used to host any type of traditionally developed User Control. Here’s how it all works:

A webpart can render a control, including a User Control using:

protected override void CreateChildControls()

{

base.CreateChildControls();

Control ctrl = Page.LoadControl("/myControls/CustomUserControl.ascx");

Controls.Add(ctrl);

}

The key piece is the Page.LoadControl(path to user control);

Here we are pointing to the relative path with respect to the SharePoint root to our custom control. By making this path a ToolPart property I hope you can see that the webpart becomes a generic placeholder. For example:

private string m_url = “”;

[Browsable(true),

Category("Miscellaneous"),

DefaultValue("/myControls/CustomUserControl.ascx"),

WebPartStorage(Storage.Personal),

FriendlyName("Relative URL to User Control”),

Description("Relative URL to User Control")]

public string UserControlURL

{

get

{

return m_url;

}

set

{

m_url = value;

}

}

This property will show up in the Miscellaneous section of the ToolParts properties section. Now or render code would look like

protected override void CreateChildControls()

{

base.CreateChildControls();

Control ctrl = Page.LoadControl(m_url);

Controls.Add(ctrl);

}

Code behind can reside in the /bin folder off the controls directory.

The SmartPart gets installed as usual but thereafter we build and deploy User Controls and deploy to the destination folder and simply configure the SmartPart to point to it.

SmartPart for SharePoint is available here.

http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=6cfaabc8-db4d-41c3-8a88-3f974a7d0abe

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

PointBridge Blogs

More from this Author

Follow Us