【问题标题】:WebPart Connections on Sharepoint. - Which Type to use?Sharepoint 上的 WebPart 连接。 - 使用哪种类型?
【发布时间】:2009-05-15 12:30:28
【问题描述】:

我编写了一个示例 webpart,它采用从 orher webpart 传递的参数并将其值显示在标签上。代码如下:

[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);
    }
}

然后我将 WP 放在一个页面上,并使用 SPD 生成一个 DataView WP,以便将文件名从 Doc 库传递给 WP。
第一次可以正常工作,但是当我选择另一个文档时,出现以下异常:

无法将“Test.Assembly.SharepointProject.DislayParameter”类型的对象转换为“Microsoft.SharePoint.WebPartPages.WebPart”类型。

这让我想... 我是否必须从 Microsoft.SharePoint.WebPartPages.WebPart 而不是 System.Web.UI.WebControls.WebParts.WebPart 继承?如果是, 既然 MSDN 和博主都建议使用后一个类,这样做的缺点是什么?

【问题讨论】:

    标签: sharepoint sharepoint-2007 web-parts


    【解决方案1】:

    我从来没有真正同意不使用特定于 SharePoint 的 webpart 子类 - 反对它的唯一原因是允许 web 部件在 SharePoint 以外的容器中运行 - 这在理论上很好,但我从来没有工作过Web 部件极有可能在 SharePoint 之外使用的项目。

    SharePoint 2003 中存在一种不同类型的 Web 部件(早于 .NET 2.0 Web 部件),这个问题也可能有点模糊 - 那是绝对不应该使用的。

    【讨论】:

    • 嗨,汤姆。我以这种方式使用它们没有任何问题......简而言之。假设我的环境在我的控制之下,那不应该造成问题!!!感谢您的回复!
    猜你喜欢
    • 2011-07-10
    • 2011-04-15
    • 2011-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-08
    • 2010-09-19
    • 2011-01-26
    相关资源
    最近更新 更多