Solved

Webpart personaiization properties

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Contant UI messages in .NET 1 41
Replacing HTML tags in Textarea/Textbox 5 29
Paging GridView 7 34
Hovering effect 9 29
I used to be SharePoint evangelist in our company, so my Outlook always full of questions about how to do this, or where I can find that. One day I found such an email with the following question: "how to attach 3-State workflow (one of the workflow…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now