CaseyMargell

I'm working on a web part that extends the Content By Query Web Part and need to expose some properties through the Modify Shared Web Part menu. I've been working through an msdn How to: Customize the Content Query Web Part by using Custom Properties article:
http://msdn2.microsoft.com/en-us/library/aa981241.aspx

However I'm getting hung up on the bit about editing the caml query bit. I don't think I need to worry about that but at this point I'm not so sure.

In my c# object I'm including the following definition to make my property visible:

private bool _showControls;

#region Public Properties
[Browsable(true),
Category("Miscellaneous"),
DefaultValue(ShowControlsDefault),
WebPartStorage(Storage.Personal),
FriendlyNameAttribute("Show Controls"),
Description("Toggles whether controls are shown")]

public bool ShowControls {
get { return _showControls; }
set { _showControls = value; }
}
#endregion

Any input anyone has is greatly appreciated. There's definitely a possibility I'm way off base here as there seems to be a lot of conflicting information floating around (plus there's the old version of sharepoint versus the new and whatnot).


Re: SharePoint - Development and Programming Exposing a property from a custom web part

BeeJay

If you are inheriting your Custom Web Part from System.Web.UI.WebControls.WebParts.WebPart, consider using this class Attributes instead.

Code Block

[

Personalizable( PersonalizationScope.Shared ),

WebBrowsable( true ),

WebDisplayName( "Instances List" ),

WebDescription( "Type the Instances List separated by semicolons (;)" )

]

public string Instances

{

get { return sInstances; }

set { sInstances = value; }

}

You don't need any entry in the dwp file for string, int and datetime.





Re: SharePoint - Development and Programming Exposing a property from a custom web part

CaseyMargell

Nope, I'm inheriting Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.




Re: SharePoint - Development and Programming Exposing a property from a custom web part

Cale Hoopes

Casey,

I'm curious. What are you having a problem with Is the property not holding its value Or are you having problems with overriding something Let us know.

I have heard that extending the Content By Query Web Part can sometimes not work because there are pieces it depends on that are sealed. I don't know that for a fact, however.

Let us know what the actual issue is.

Cale Hoopes

Ascentium Corporation

caleh@ascentium.com





Re: SharePoint - Development and Programming Exposing a property from a custom web part

CaseyMargell

Hi Cale,

The problem appears to the fact that I'm extending the Content By Query Web Part. I'm exposing properties to the UI with two other generic web parts that I've developed just fine. I was doing the custom Content Query Web Part one first and thus I was banging my head against a brick wall trying to get it to work. When I tried the exact same thing in my web parts that inherit from the generic WebPart class then the properties are being exposed to the ui just fine.

I'm not sure what the issue is but I'm working around it for the time being by importing a modified .webpart file with the desired values for my properties.

Casey




Re: SharePoint - Development and Programming Exposing a property from a custom web part

Dove


Hi Casey,

Got the same problem here...

I looked a bit into it.

In fatc the GetToolParts() from ContentByQueryWebPart is redefined so it doesn't instanciate a CustomPropertyToolPart, which is needed to handle your [WebBrowsable] properties.

So you could try this in your inherited class :

public override ToolPart[] GetToolParts()
{
List<ToolPart> res = new List<ToolPart>(base.GetToolParts());
res.Insert(0, new CustomPropertyToolPart());
return res.ToArray();
}


But it would show some 'hidden' properties of the ContentByQueryWebPart (eg "Enable Data View Caching")...

So it seems you have no choice but to implement your own ToolPart class to handle your custom props...