Archive for the ‘Toolpart’ Category


Posted: October 23, 2009 in Toolpart

I have already created a post oncreating a toolpart.

There is a more simpler way to provide a toolpart and to read values from it.

You just need to do two things

  • Create a property of the required type.
  • access that property same as a normal variable.

For Example in the below code I am getting a string variable and displaying that in the label in the webpart.

public partial class CFReport : System.Web.UI.UserControl
         public string UserName
              get { return userName; }
              set { userName = value; }
        protected void Page_Load(object sender, EventArgs e)

             this.lblName.Text = this.UserName;

Here UserName will be a property that will appear in the toolpart and here the value that is entered will be displayed in the label.


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: “);

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.