Create a Visual Web Part project in Visual Studio. In the file VisualWebPart1.cs, add your custom properties:
The Personalizable attribute is what tells is the Web Part framework to store this property in the database. The WebBrowsable attribute is what tells the Web Part framework to make this property visible in the Edit Web Part properties pane. The WebDisplayName attribute changes the display name visible within the Edit Web Part properties pane. In this case, if we did not alter the display name, it would appear as CustomProperty. Since we have now altered the display name to include a space, these two words will not run together. The Category attribute will change what section of the Edit Web Part properties pane this setting will appear in. If not specified, the custom property will appear in a Miscellaneous section.
In the file VisualWebPart1UserControl.ascx.cs, add a property to store our custom web part.
Now, back in the VisualWebPart1.cs file, alter the CreateChildControls() method to pass this web part into our user control.
Now, in the VisualWebPart1UserControl.ascx.cs file, update the code to display the value entered for our custom property in a label we have added to our VisualWebPart1UserControl.ascx file.
Now deploy your web part and add it to your page. When we go to edit our web part, we see there is a section called Custom Settings which contains our property.
Upon entering text into this field, hitting OK, and saving the page, we will now see our text appear in the label for our web part.
Fuente:
Más información:
http://blog.concurrency.com/sharepoint/create-a-custom-web-part-for-sharepoint-2010/
http://allaboutmoss.com/2010/04/05/webpart-development-part-4-creating-custom-web-part-properties/
No hay comentarios:
Publicar un comentario