Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a user control which is deployed as a web part by using SmartPart.

I would now like to be able to define a property and have the value stored in the user's storage space. I guess I need to be able to trigger the dirty flag (SetPersonalizationDirty()) somehow when the property is changed programmatically.

How should I do this?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

I don't believe the SmartPart is built to support your requirement and you'd need to do one of two things:

  • Create your own webpart from scratch that calls the ascx, passing it the personalized property
  • Extend the smartpart, customising the piece that loads the ascx, passing it the personalized property

To me, it sounds like a good time to move beyond the smartpart. It's pretty simple to create a webpart that loads a usercontrol anyways.

This article on msdn talks includes samples and guidance on how to support personalization in a webpart. Your custom property will look something like the code below:

// Create a custom category in the property sheet.
[Category("Custom Properties")]
// Assign the default value.
[DefaultValue(c_MyStringDefault)]
// Property is available in both Personalization
// and Customization mode.
[WebPartStorage(Storage.Personal)]
// The caption that appears in the property sheet.
[FriendlyNameAttribute("Custom String")]
// The tool tip that appears when pausing the mouse pointer over
// the friendly name in the property pane.
[Description("Type a string value.")]
// Display the property in the property pane.
[Browsable(true)]
[XmlElement(ElementName="MyString")]
// The accessor for this property.
public string MyString
{
    get
    {
        return _myString;
    }
    set
    {
        _myString = value;
    }
}
share|improve this answer
    
+1 thanks for the reply. I have been trying to do what you say. I thought it should be easy to load a user control but got nowhere with it. Kept getting errors like '/_usercontrols/xyz' not found. Or Security exceptions. Can you point me at a good walk-thru for this? Would appreciate it :-) –  paul Jan 31 '11 at 14:05
    
Something like a2zdotnet.com/View.aspx?Id=95 is pretty accurate. Alternatively vspug.com/mirjam/2009/02/11/… The principle is simple, you just need to make sure you're pointing to the right location (which can be tricky to figure out sometimes. A little trial and error should sort it out. –  Neil Richards Jan 31 '11 at 14:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.