WebPart Connections on Sharepoint. - Which type to use?
I wrote a sample webpart that takes a parameter passed from the orher webpage and displays its value on a label. Here is the code:
[Guid("11a885e9-13e1-4c6e-8045-e5575794ebd8")]
public class DisplayParameter : System.Web.UI.WebControls.WebParts.WebPart
{
protected Label _label = new Label();
private string _message;
[ConnectionConsumer("Parameter to show")]
public void GetWPConnectedProviderInterface(IWebPartField connectProvider)
{
FieldCallback callback = FieldCallback;
connectProvider.GetFieldValue(callback);
}
private void FieldCallback(object fieldValue)
{
_message = (string)fieldValue;
}
protected override void OnPreRender(EventArgs args)
{
if (string.IsNullOrEmpty(_message))
_label.Text = "No Message.";
else
_label.Text = _message;
}
protected override void CreateChildControls()
{
base.CreateChildControls();
Controls.Add(_label);
}
}
Then I put WP on the page and WP DataView generated with SPD to pass the filename from the Doc library to WP.
It works fine the first time, but when I select another document, I get the following exception:
Cannot pass object of type 'Test.Assembly.SharepointProject.DislayParameter' for input 'Microsoft.SharePoint.WebPartPages.WebPart'.
This makes me think ... Should I inherit from Microsoft.SharePoint.WebPartPages.WebPart instead of System.Web.UI.WebControls.WebParts.WebPart ?, and if so, what are the disadvantages of doing this since MSDN and bloggers suggest using the latter class?
a source to share
I never agreed that I was not using a SharePoint subclass for the website. The only reason it might be allowed for a web part in non-SharePoint containers is fine in theory, but I've never worked on a project where there is the slightest chance the web part will be used outside of SharePoint.
The issue may also be slightly overshadowed by the existence of another part of the Web Part in SharePoint 2003 that predates .NET 2.0 Web Parts — one that should definitely not be used.
a source to share