Aidan Garnish
MOSS 2007 and other Microsoft technologies

Setting custom properties on web parts

December 3, 2007 10:49 by aidan

When creating web parts it is often useful to allow users to supply some additional parameters to the web part. This can be done by adding custom attributes which can then be set by the user and used in your code.

To do this use the following syntax:

   [Personalizable(PersonalizationScope.User),
         WebBrowsable, WebDisplayName("Products List"),
         WebDescription("Use this property to change list used to retrive products from")]
        public string ProductList
        {
            get { return strProductsList; }
            set { strProductsList = value; }
        }

In this case, rather than hard coding the name of the products list, the user is able to specify which list to use.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Comments

December 3. 2007 11:28

Trackback from SHAREPOINTBlogs.com Mirror

Setting custom properties on web parts

SHAREPOINTBlogs.com Mirror

December 3. 2007 22:46

It is worth noting that this is just one of the formats that can be used - The example you give is the v3 format, which while it is the best one to use, will break if you don't also use the v3 format for the .webpart file. .dwp files are usually v2 format, but I don't think that is enforced.

More details on my blog:

www.tqcblog.com/.../...ces-in-webpart-formats.aspx

Tom Clarkson

Add comment


 

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

January 6. 2009 15:31