Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Webpart personaiization properties

Posted on 2013-10-26
5
Medium Priority
?
325 Views
Last Modified: 2013-10-27
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.
0
Comment
Question by:BobHavertyComh
  • 2
  • 2
5 Comments
 
LVL 32

Expert Comment

by:Jamie McAllister MVP
ID: 39602932
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!).
0
 
LVL 9

Author Comment

by:BobHavertyComh
ID: 39602955
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.
0
 
LVL 32

Accepted Solution

by:
Jamie McAllister MVP earned 2000 total points
ID: 39603000
The Personalization Directive appears directly above the ButtonText property. That's what links them.

You need a Personalization directive per property you want to persist. It doesn't do multiple properties.
0
 
LVL 9

Author Closing Comment

by:BobHavertyComh
ID: 39603024
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.
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39603563
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
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question