Solved

Webpart personaiization properties

Posted on 2013-10-26
5
320 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 31

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 31

Accepted Solution

by:
Jamie McAllister MVP earned 500 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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