Joel's SharePoint Architect Blog

SharePoint 2013 Training, Architecture, Administration and Development

Subscribe Subscribe  View Joel Jeffery's profile on LinkedIn
joelblogs.co.uk | joelj.co.uk | joeljeffery.co.uk | jfdiphoenix.co.uk

Posts Tagged ‘Development’

This question was asked by one of my (most excellent) students this week:

In an ASP.NET Web Part for SharePoint, when I override CreateChildControls(), do I need to invoke the base?

You will see many examples on the Internet of code that does invoke the base, and many counter examples. Some of these contradictory examples are on the Microsoft MSDN site!

I decided to take ILSpy to the System.Web.dll assembly and find out once and for all.

First of all, System.Web.UI.WebControls.WebParts.WebPart does not override CreateChildControls() itself.

System.Web.UI.WebControls.WebParts

So, we must take a look at it’s ancestor: Part.

System.Web.UI.WebControls.WebParts.Part

Once again, there is no implementation for CreateChildControls() here, so we go further up the chain to System.Web.UI.WebControls.Panel:

System.Web.UI.WebControls.Panel

Still no definition of CreateChildControls(). Further up, we get System.Web.UI.WebControls.WebControl.

System.Web.UI.WebControls.WebControl

But it is not until we get to System.Web.UI.Control that we have an implementation:

System.Web.UI.Control

Hang on a moment! That’s empty!

// System.Web.UI.Control
/// <summary>Called by the ASP.NET page framework to 
/// notify server controls that use composition-based 
/// implementation to create any child controls they contain
/// in preparation for posting back or rendering.</summary>
protected internal virtual void CreateChildControls()
{
}

So, the simple answer appears to be:

No, you don’t need to invoke base.ControlChildControls() in an ASP.NET WebPart”

Technorati Tags: ASP.NET, Development, SharePoint 2010, SharePoint Development

Updated SharePoint 2010 Google Maps Web Part (v1.2)

There’s an updated version of the SharePoint 2010 Google Maps Web Part available for download here: http://sp2010googlemaps.codeplex.com

We’ve fixed a bug with multi-line labels. :o)

Works on-premise, in the Sandbox and in Office 365.

Technorati Tags: Development, Office 365, SharePoint, SharePoint 2010, SharePoint Development, Solution Sandbox

After much persuasion, I’ve decided to fly in the face of public opinion and record one of the songs from my SharePoint show Smile

Stop, Collaborate and Listen:
SharePoint’s Back with a Brand New Invention.

Technorati Tags: Comedy, Development, SharePoint, SharePoint 2010 Training, Songs, Videos

I was recently asked how to remove the Editor Parts (Appearance, Layout, Advanced, etc) from custom Web Parts.

One strategy is to implement your own Editor Part and mark the built-in ones as not Visible.

Firstly, we need to create our Editor Part class:

class MyEditorPart : EditorPart
{
    protected override void CreateChildControls()
    {
// this line hides the default EditorParts Parent.Controls[2].Visible = false; base.CreateChildControls(); } public override bool ApplyChanges() { // do stuff here return true; } public override void SyncChanges() { // do stuff here } }

And here’s how we invoke our Editor Part from our Web Part:

public class MyWebPart : WebPart
{
    public override EditorPartCollection CreateEditorParts()
    {
        ArrayList aryParts = new ArrayList();

        MyEditorPart myEditor = new MyEditorPart();
        myEditor.ID = this.ID + "_myEditorPart";
        aryParts.Add(myEditor);

        return new EditorPartCollection(aryParts);
    }
    // do more stuff here...
}

Hopefully, when you edit the Web Part it should look something like this:

The next step would be to extend CreateChildControls(), ApplyChanges() and SyncChanges() to get and set any properties you’d like to allow users to edit.

Technorati Tags: Development, SharePoint, SharePoint 2010 Training, SharePoint Developer, SharePoint Development, WebParts

If you’re creating or editing a JavaScript file in Visual Studio and you would like some help creating Client Object Model code, you’re not alone.

It’s a little bit cryptic, but we can tell IntelliSense to include any JavaScript libraries you have on your development machine.

Simply place the following two lines at the top of your source code (watch out for line breaks!):

/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\MicrosoftAjax.js" />
/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\SP.debug.js" />
/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\SP.Core.debug.js" />

Then, you can get IntelliSense when you need it the most!

Enabling IntelliSense for the JavaScript Client Object Model in SharePoint 2010

Full article on MSDN available here.

Enjoy!

Technorati Tags: Development, SharePoint 2010, SharePoint 2010 Training, SharePoint Developer, SharePoint Training