How to use VS to create a simple custom Web Part widget property

Source: Internet
Author: User

Custom attributes Expand your Web Part widget with additional options and settings. This article explains how to create a simple custom Web Part widget property using Visual Studio.

1. Open Visual Studio and click on the file--new project--blank SharePoint Project Customwpproperties. Deployed as a farm solution.

2. Right-click the item Add New Item Web Part widget wppropertyexample, click Add.

3. Right-click WPPropertyExample.cs and click View Code.

4. Add the code, and finally it's like this:

Using System;
Using System.ComponentModel;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using Microsoft.SharePoint;
Using Microsoft.SharePoint.WebControls;
Using System.Xml.Serialization;
Namespace Customwpproperties.wppropertyexample
{public
class Wppropertyexample:webpart
{
Label Lbltitle = new label ();
Public enum sharepointlists
{
Stats, products
,
Customers,
}
protected Sharepointlists listoflist;
[Personalizable (Personalizationscope.user),
WebBrowsable,
webdisplayname ("Available Lists"),
webdescription ("Available Lists in SharePoint Site.")]
Public sharepointlists mysticks
{get
{return listoflist;}
set {listoflist = value;}
}
protected override void CreateChildControls ()
{
Lbltitle.text = "Web part with";
This. Controls.Add (Lbltitle);}}

5. Click Build--Deploy the solution.

6. On the SharePoint site, click the Site Action-edit page-Add the Web Part, select Wppropertyexample in the custom class, and click Add.

7. Edit this Web Part, as you can see in the Properties pane:

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.