[CORRECTION/UPDATE: September 2007] You should always inherit from the ASP.NET WebPart class. You should never EVER use Microsoft.SharePoint.WebPartPages.WebPart. NEVER. EVER. The correct method to use to get the tool panes for ASP.NET Web Parts is "CreateEditorParts".
A nice touch in custom web parts is a link to initialize the web part. A good example of this is the content editor web part– add one to your page and you’ll get a friendly message, "To add content, open the tool pane and then click Rich Text Editor." This is relatively easy to do using the ToolPane.GetShowToolPaneEvent method. Unfortunately, this method expects a Microsoft.SharePoint.WebPartPages.WebPart, and the desired base class for v3 development is the ASP.NET WebPart. (Note that this is still an issue for B2TR– but I doubt Microsoft will fix this for RTM.)
Luckily, ToolPane has another method called "GetShowExtensibleToolPaneEvent" that does almost what we want, and takes the webpart ID as the argument. The link that it passes back though opens the ExtensibleView of the web part– and I’m not sure how to get at that, it’s a blank toolpane window that would be cool to use but I’m not sure how. (If you know how, please share that info with me!) But simply replacing the javascript argument "ExtensibleView" with the argument "Edit" will do the trick.
Incorporating the previous security code example, here’s a Web Part method (safe for a System.Web.UI.WebControls.WebParts.WebPart or a SharePoint WebPart) that adds a control to open the SharePoint toolpane if the user has the correct rights.
/// <summary>
/// Adds a control to initialize the WebPart.
/// </summary>
protected void AddInitializeControl()
{
bool hasRights = ((ISecurableObject)SPContext.Current.Web).DoesUserHavePermissions((SPBasePermissions)Microsoft.SharePoint.SPPermissionGroup.WebDesigner);
if (!hasRights)
return;
string editLink = Microsoft.SharePoint.WebPartPages.ToolPane.GetShowExtensibleToolPaneEvent(string.Format(@"’{0}’",this.UniqueID));
this.Controls.Add(new LiteralControl(
string.Format(@"<br/><a href=""javascript:{0}"">Initialize WebPart</a><br/>",
editLink.Replace(@"ExtensibleView", @"Edit"))
));
}
—————–
UPDATE:
The supported way to add custom toolpanes to the ASP.NET WebPart class is through implementing the ICustomizeToolPane interface, with a method like the following. HOWEVER– this is buggy, and throws an InvalidOperationException from the ASP.NET WebPart. Also of note, unless you tweak the verb menu, this will be a different toolpane view than the EditWebPart view. Regardless, here’s the syntax:
public void CreateToolPaneControls(Microsoft.SharePoint.WebPartPages.ToolPane toolpane)
{
LocationEditorPart locEditor = new LocationEditorPart(this);
toolpane.InsertToolPart(0, locEditor);
Microsoft.SharePoint.WebPartPages.WebPartToolPart standardToolPart = new Microsoft.SharePoint.WebPartPages.WebPartToolPart();
toolpane.InsertToolPart(1, standardToolPart);
}
So in the meantime– and in case this doesn’t change before WSSv3 RTM, it seems the only supported way to implement custom tool panes is to implement from the Microsoft.SharePoint.WebPartPages.WebPart and override the GetToolParts method, like so:
public override Microsoft.SharePoint.WebPartPages.ToolPart[] GetToolParts()
{
List<ToolPart> parts = new List<ToolPart>();
parts.AddRange(base.GetToolParts());
parts.Insert(0, new LocationEditorPart(this));
return parts.ToArray();
}
So while the documents say "you should design Web Parts that inherit from the ASP.NET 2.0 System.Web.UI.WebControls.WebParts.WebPart base class whenever possible", you really need to inherit from the Windows SharePoint Services WebPart class if you’re doing anything interesting with the SharePoint tool pane. This does affect the DWP/WebPart file, as the .webpart file is incompatible with the SharePoint WebPart which must use the .dwp file. However, I still use my favorite tool for the webpart galley (instead of hand-writing the dwp): http://localhost/_catalogs/wp/Forms/AllItems.aspx and http://localhost/_layouts/NewDwp.aspx.
徵信是個富有挑戰的工作,忙碌、刺激、激情。最后的結局總是有人哭,有人笑。在徵信社工作的幾年時間里,我感悟到很多生活的無奈與殘酷。閑暇時我去中古车市场,感覺工作太緊張,放松一下而已,不是純粹的為了淘二手车。私家偵探也就是徵信工作人員似乎是個很酷的詞,但是如果誰需要私家偵探來幫忙的話,他(她)的婚姻也許已經亮起了紅燈。每天陪著星際客戶喝著咖啡,似乎是一件很爽的事,可是她們的眼淚比咖啡要苦的多。常常聽他們說嘈雜的燈光音響麻痹著他們的神經,讓他們過著醉生夢死的生活。其實,誰不渴望幸福美滿的愛情。沒有團體制服不了那些玩弄生活、玩弄感情的人,于是,徵信社應運而生。這不知道是人們的福音還是不幸,希望天下的每一個人都歡樂著、幸福著。坐月子是女人一生的大事,女人可以为了襁褓中的婴儿放弃一直引用的红酒而吃月子餐,这时候的女人是幸福而伟大的。有人歡喜有人優,有人狂笑有人大哭,我不想看到女人太多的眼淚,辭職后,我做了一位安靜、平和的室內設計師。虽然上下班没有了车接车送,但我租车怡然自得。偶爾和ecosway的朋友小聚,很愜意!
Cheap wOW Gold , buy wOw Gold We supply cheap wOW Gold, to reliable customers. welcome to Wow gold, buy WOW GOld sell.
Hi,Do you need advertising displays, digital signages, mp4 advertisement players, SD card players and advertisement LCD displays? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.
amberdigital Contact Us
website:www.amberdigital.com.hk
alibaba:amberdigital.en.alibaba.com[bfiiaicidafifc]