I have a webpart which I extend and i would like to programmatically add extra fetched properties to those that already exist, but I cannot succeed in that, maybe you could be of help to me.

So here it the piece of code i have:

    public MyCustomWebpart()
        this.SelectColumns = AddExtraFetchedProperties(this.SelectColumns);


Note: AddExtraFetchedProperties this method add few extra columns to the xml.

But the problem is that on the time I'm in constructor the SelectColumns or PropertiesToRetrieve properties are empty, and I'm not sure what is the difference between those 2. If in constructor i pass just a correct xml with the properties it is ok, it works fine, BUT i want to ADD extra properties to existing one, and not override everything.

Any idea how to do that?

PS: i tried to set it in onInit or onprerender method but no real success in it, it is still being overwritten by some default values ...

  • Just to confirm - if you set the property value in the OnPrerender method SelectColumns is not null, the value is set but soon after the old value is somehow restored? Which webpart are you extending?
    – SPArcheon
    Commented Mar 4, 2013 at 11:49
  • im not setting is not null, im just assigning my value to it, it is search results core webpart
    – Shkipper
    Commented Mar 4, 2013 at 12:06
  • Yes, what I meant was that in the constructor the value of SelectColumns is null while in the OnPrerender method you see the actual value from the web part setting right? Then, if you try to change the default value while still in the OnPrerender method, it somehow reset to the default value later?
    – SPArcheon
    Commented Mar 4, 2013 at 13:10
  • Yep, somehow i get the default old value without my extra fields, i debugged whole the webpart, my xml is valid with the columns for selectedColumns property, but then at the end if i verify the webpart on the page and i check the propertie of webpart, i see the column but without my 2 extra columns, although in constructor if i set all the 10 properties defualt + mine own, then it works fine
    – Shkipper
    Commented Mar 4, 2013 at 13:18
  • So, it works if in the costructor you manually set the SelectedColumns property to include all the 10 prop, but it doesn't work if you calculate the same property value with the AddExtraFetchedProperties method and use its return value to set the property?? If that is the case, I would check if the result from the AddExtraFetchedProperties is the same value you set manually.
    – SPArcheon
    Commented Mar 4, 2013 at 14:00

1 Answer 1


In order for your changes to stick, you have to do three things:

  • set UseLocationVisualization to false
  • set PropertiesToRetrieve to an empty string
  • set SelectColumns to the XML for the properties you want included

I'm not sure if there is a way to just add the few extra columns you want, I think all you can do is override everything, so you will have to include the default columns along with the ones you want to add.

See this blog post.

  • you think in what step it should happen? because in the constructor i cannot do that, as those properties are still empty, should i do it onInit or onPreRende method? or ...?
    – Shkipper
    Commented Mar 5, 2013 at 6:49
  • In the blog post I linked to above, the guy does it in the OnInit. In my own situation, I did it through a feature receiver. When my feature was activated on the search center site, it found the results page, grabbed the core results web part, made the changes, then saved the changes to the web part. That way all the custom information is already there, I don't have to add it every time the web part is rendered. Commented Mar 5, 2013 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.