SharePoint 2010 Using multiple instances of a custom Visual Webpart with properties

I already posted about the properties for your custom web part. Each webpart has a property toolbox by default. If you develop your own web part, you might want to make it more flexibel and provide a property toolbox for the endusers. But then it makes also sense, that you can use the webpart more than once at a page or in a website of a site collection.  In order to achieve this, i will go through my example web part where i used some settings. And finally it might help you, too.

We look at Webpart.cs:

//Property for RowLimit
private int _rowLimit = 10;
WebDisplayName("Row Limit"),
WebDescription("Row Limit"),
Category("Search Results")]
public int rowLimit
get { return _rowLimit; }
set { _rowLimit = value; }

We have a private variable and the rest you should know. It should not be static (_rowLimit).

We look at WebPartUserControl.ascx.cs

public SearchWebPart WebPart

protected void Page_Load(object sender, EventArgs e)
this.WebPart = this.Parent as SearchWebPart;


This is how we access in the user control the properties of the webpart. We make a connection to the search webpart and its properties and afterwords we can call them simply by using:


That’s it. Hope it helps you.


The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

Karsten Schneider
About Karsten Schneider 302 Articles
He is Consultant for SharePoint Solutions for collaboration, communication and business processes. He provides his customers applications based on standard features as well as development or combining the power of several microsoft tools like Dynamics CRM. In his free time he tries to collect tipps and worthy experience in this blog.

1 Comment

Leave a Reply

Your email address will not be published.