Link to home
Start Free TrialLog in
Avatar of Arnold Layne
Arnold LayneFlag for United States of America

asked on

Webpart personaiization properties

public class BasicWebPart : WebPart
    {
        Button btn = null;
        LiteralControl literal = null;
        [Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("Button Text"), WebDescription("displays button text"), Category("Configuration")]
        public string ButtonText { get; set; }
        protected override void CreateChildControls()........

This show up in the webpart  editor under a new group called configuration, and it shows up as a text box. I can understand why because the property is a string. But why does the Personalizable attributes automatically relate to the ButtonText property? And what would happen if i added other properties? I don't see any sort of encapsulation (or whatever) that would relate the Personalizable attributes to the ButtonText property.
Avatar of Jamie McAllister
Jamie McAllister
Flag of Switzerland image

This was in an example, or prefilled when you created a web part in a project?

There's no automatic mapping of web part properties to controls. This has been added in by someone or as part of the template.

The Personalizable block just ensures that a property can be filled in and persisted. It's usually up to the developer to retrieve those properties and apply them to controls or whatever else. You can add as many such properties as you want but you have to do the plumbing yourself (unless something whizzy has been added to Visual Studio!).
Avatar of Arnold Layne

ASKER

This is a small part of larger code from a vid course that never explains why it is doing something, it just tells you to do it.

The Personalizable block just ensures that a property can be filled in and persisted.

I understand that, and it is persisting. But what relates the Personalization block to the ButtonText property? I haven't gotten to linking or binding this to certain controls yet. Does the Personalization block merely relate to any and every property declared within the class? So if I created three other properties below the ButtonText property, would the same personalization block apply to all three? And, if I wanted to dictate different personalization attribute sets to different properties, then I suppose I would have to make a different personalization block with different attributes for each property  But what tells it to relate each block to each property? Is it just because it is the line before the property it is supposed to relate to?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Jamie McAllister
Jamie McAllister
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Okay, thanks. As long as I know that I must do this. It's very odd, but if that's the rule, that's the rule. I wish this course would mention that because it is not immediately intuitive.
Hi,
just to add some general comment (as Jamie is completely right):
Personally I find learning vids/courses quite helpful. But the most I got from special books - as they normally tend to explain why things have to be done like this.
One of the very best books has been the old "Inside Windows SharePoint Services 3.0" from MS Press written by Ted Pattison. There are also two good books from MS Press "Inside SharePoint 2010" and "SharePoint 2010 Developer Reference" - they cover most topics (but are overlapping a lot) - but if you have the time and work through each chapter you could bring your experience to another level.

But the main learning benefit is by doing things in the real world :-)

Just my 2ct
Rainer