Getting widget instance properties

Yehuda Lando asked on July 27, 2014 19:07

Hi,

Anyone knows how can I get a certain widget instance properties? I would like to get and set them when a certain setting key is set.

Thanks

Recent Answers


Brenden Kehren answered on July 28, 2014 01:05

You'd have to create your own webpart with those rules in place and then create a new widget instance of that webpart (since a widget is a webpart with properties already set).

0 votesVote for this answer Mark as a Correct answer

Yehuda Lando answered on July 28, 2014 01:20

My issue is how to get those properties, in general I will use an event handler

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 28, 2014 15:21

Right, in your webpart create the event handler and set the property just as you normally would.

0 votesVote for this answer Mark as a Correct answer

Yehuda Lando answered on July 30, 2014 07:58

Sorry, I wasn't clear. I want to get those properties from a global event handler (when the user changes a setting).

My web part has 4 path selectors, which allows the user to select a document. If the user enables a certain setting key, I want to move the selected documents to a different path, and update the selected paths.

I have the widget set up already, and I know how to get/set it's properties from the web part code, but not from outside it. I'm guessing I need to get the template info, then the web part zone, which I did, but I'm stuck at this stage.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 30, 2014 21:42

So when the setting is updated you want to perform actions to documents right? Then you need to look at the global event handler for the SettingsKeyInfo object. Take a look at that documentation. To get you started you can create this global event and perform you actions after that event has taken place (i.e.: updating/moving documents).

SettingsKeyInfo.TYPEINFO.Events.Update.After += Update_After;
0 votesVote for this answer Mark as a Correct answer

Yehuda Lando answered on July 30, 2014 22:42

Yea, that I know how to do. My issue is how to get the web part properties inside this event handler.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 1, 2014 13:58 (last edited on August 1, 2014 13:58)

I see what you're trying to do and it's a great idea. I don't believe you can go directly to the webparts properties without knowing the page template they are used in.

So your steps would be to:

  1. go through all the pages on your site,
  2. find all the page templates those pages are using,
  3. look through the webparts on that template,
  4. see if the webpart is of type lets say repeater,
  5. check the property value and
  6. possibly move the document based on the value you find.
0 votesVote for this answer Mark as a Correct answer

Yehuda Lando answered on August 2, 2014 03:27

Ok, I tried some things and realized it's much simpler than I thought. I was looking for some info providers to do this after I got the template instance.

This is how I did it:

var pageInfo = PageInfoProvider.GetPageInfo(SiteContext.CurrentSiteName, "/Main", "en_US", "/", true);
var zone = pageInfo.TemplateInstance.WebPartZones.First(z => z.ZoneID == "zoneTopArticles");
var webPart = zone.WebParts.First(w => w.ControlID.ToLower() == "toparticlesrepeaterwidget");

var nodeId = webPart.GetValue("FirstArticle");
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.