Adding a Web Part Property After adding the new Web Part, add a property that can be personalized for the Web Part. The Web Part property determines the text that is rendered inside the Web Part. This is personalized based on the individual user.
For more information about customization and personalization, see Web Parts Personalization. |
For Web Parts based on the ASP.NET Web Parts Pages base class, the tags that are used for the customizable properties are named differently than Web Parts that are based on the WebPart base class. The following list describes each of those properties:
1. In the DisplayMessageWebPart file, copy and paste the following code to create a basic customizable property. private string customMessage = "Hello, world!"; public string DisplayMessage { get { return customMessage; } set { customMessage = value; } } 2. Add the following tags above the public declaration to allow changes on a per-user basis. [WebBrowsable(true), WebDescription("Displays a custom message"), WebDisplayName("Display Message"), Personalizable(PersonalizationScope.User)] Now you have created a personalizable Web Part property.
Interested in mastering SharePoint Training? Enroll now for FREE demo on SharePoint Training.
Overriding the CreateChildControls Method Next, you must add functionality to your Web Part. By overriding the CreateChildControls method, you can tell the Web Part what operations to perform when the page is visited. In this example, the Web Part renders the user-defined text.
protected override void CreateChildControls() { base.CreateChildControls(); LiteralControl message = new LiteralControl(); message.Text = DisplayMessage; Controls.Add(message); }
You liked the article?
Like : 0
Vote for difficulty
Current difficulty (Avg): Medium
1/15
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.
Stay Updated
Get stories of change makers and innovators from the startup ecosystem in your inbox