?
Solved

Webpart personaiization properties

Posted on 2013-10-26
5
Medium Priority
?
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

719 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