Toolpart in Sharepoint

Posted: October 7, 2008 in Toolpart

Toolpart is basically used in sharepoint when you want to give some input to the webpart from the website. It is same like the tollpart that is available for the normal web parts.
Here is the sample code for creating a toolpart.

namespace ACBS.ClientRequest
{
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

public class RelatedRequestsToolPart : ToolPart
{
private TextBox txtRequestLevel;
private string strRequestLevel;

public RelatedRequestsToolPart()
{
this.Title = “Related Requests ToolPart”;
this.Init += new EventHandler(this.RelatedRequestsToolPart_Init);
}

public override void ApplyChanges()
{
((RelatedRequestsWebpart)this.ParentToolPane.SelectedWebPart).RequestLevel = Convert.ToString(Page.Request.Form[strRequestLevel]);
}


protected override void RenderToolPart(HtmlTextWriter output)
{
txtRequestLevel = new TextBox();
txtRequestLevel.ID = strRequestLevel;
txtRequestLevel.Text = ((RelatedRequestsWebpart)(this.ParentToolPane.SelectedWebPart)).RequestLevel;
output.Write(“Request Level: “);
txtRequestLevel.RenderControl(output);
base.RenderToolPart(output);
}

protected void RelatedRequestsToolPart_Init(object sender, EventArgs e)
{
this.strRequestLevel = “txtRequestLevel”;
}
}
}

Here txtRequestlevel is the input thet you will provide when you deploy the webpart in your site.

Advertisements
Comments
  1. […] I have already created a post on creating a toolpart [ Toolpart ]. There is a more simpler way to provide a toolpart and to read values from […]

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