If you have designed SharePoint 2010 vintage web parts before, you know that you can easily determine customized made web element qualities which your web element code-behind can eat.
With the reputation of SharePoint 2010 Graphic Webpart, you are probably interested in having customized made qualities identified there too.
There are few items different about revealing your customized made qualities in a Graphic Web par
Let’s see the steps involved:
Add new or use existing Visual Web Part to your project, in our case called Webpart1
Open the Webpart1.cs file which will look something like this:
- Update your CreateChildControls logic to look like this:
- Switch to your user control … Webpart1UserControl.ascx.cs
and add your custom property definition right below the CreateChildControls method, in our case the property will look something like this:
In here, the PropertyValue is the actual variable which will be later consumed by your web part user control.
This piece here will pass in the properties every time the control is reloaded. In here, the only change you’ll need to make is to rename Webpart1UserControl to the [name of your webpart]UserControl. This will reference the ASCX used for the Visual Webpart.
and define public variable right below the class declaration:
Here the Webpart1 is referencing the actual web part class file (not ASCX).
That’s all, in your code you can get a hold of the web part property value by using this: this.WebPart.PropertyValue, where the PropertyValue is the name of the variable we’ve chosen earlier.