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:
[sourcecode language=”csharp”]
//Property for RowLimit
private int _rowLimit = 10;
[WebBrowsable(true),
WebDisplayName(“Row Limit”),
WebDescription(“Row Limit”),
Personalizable(PersonalizationScope.Shared),
Category(“Search Results”)]
public int rowLimit
{
get { return _rowLimit; }
set { _rowLimit = value; }
}
[/sourcecode]
We have a private variable and the rest you should know. It should not be static (_rowLimit).
We look at WebPartUserControl.ascx.cs
[sourcecode language=”csharp”]
public SearchWebPart WebPart
{
get;
set;
}
protected void Page_Load(object sender, EventArgs e)
{
this.WebPart = this.Parent as SearchWebPart;
…
}
[/sourcecode]
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:
[sourcecode language=”csharp”]
this.WebPart.rowLimit
[/sourcecode]
That’s it. Hope it helps you.
..:: I LIKE SHAREPOINT ::..
This article helps me to figure out my web part issue. Thanks a lot for the tips.