属性丢失 webpart toolpart moss 2007

发布于 2024-10-03 04:09:41 字数 162 浏览 10 评论 0原文

我遇到了以下问题:

我使用 ToolPart 创建了一个 WebPart, 该工具部分有多个控件(文本框、下拉列表...) 当我填写所有内容并申请时,一切顺利, 即使我按确定。但当我回到 编辑->修改webpart,我输入的所有数据都消失了。 我该如何解决这个问题?

谢谢

I've got the following problem:

I created a WebPart with a ToolPart,
this toolpart has multiple controls (textbox, dropdownlist, ...)
when I fill in everything and apply, it all goes ok,
even when i press ok. But when i go back to
edit -> modify webpart, all my data i've entered is gone.
How can i solve this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

宁愿没拥抱 2024-10-10 04:09:41

您需要将工具部件中的值保存在 Web 部件的属性中。例如,假设我想保存一个字符串“Title”...在 Web 部件中定义一个属性:

private const string DEFAULT_WPPColumnTitle = "Title";
private string _WPPColumnTitle = DEFAULT_WPPColumnTitle;

[Browsable(false)]
[WebPartStorage(Storage.Shared)]
public string WPPColumnTitle
{
    get { return this._WPPColumnTitle; }
    set { this._WPPColumnTitle = value; }
}

我总是使用前缀“WPP”来保留所有 web p 艺术p属性在一起。

然后,在工具部件的 ApplyChanges 覆盖中,将控件的值 (_ddlColumnsTitle) 保存到 Web 部件 (WPPColumnTitle):

/// <summary>
/// Called by the tool pane to apply property changes to
/// the selected Web Part.
/// </summary>
public override void ApplyChanges()
{
    // get our webpart and set it's properties
    MyCustomWebPart et = (MyCustomWebPart)ParentToolPane.SelectedWebPart;
    et.WPPColumnTitle = _ddlColumnsTitle.SelectedValue;
}

最后,如果用户已经编辑了属性,我们希望工具部件预先填充用户的配置。在 Toolpart 的 CreateChildControls() 方法中,初始化控件:

protected override void CreateChildControls()
{
    try
    {
        MyCustomWebPart et = (MyCustomWebPart)ParentToolPane.SelectedWebPart;

        // ... code to create _ddlColumnsTitle and add it to the Controls

        // default our dropdown to the user's selection
        ListItem currentItem = _ddlColumnsTitle.Items.FindByValue(et.WPPColumnTitle);
        if (null != currentItem)
        {
            _ddlColumnsTitle.SelectedValue = currentItem.Value;
        }
    }
    catch (Exception ex)
    {
        _errorMessage = "Error adding edit controls. " + ex.ToString();
    }
}

You'll need to save the values from the Toolpart in the webpart's properties. For example, lets say I want to save a string for "Title"... in the webpart define a property:

private const string DEFAULT_WPPColumnTitle = "Title";
private string _WPPColumnTitle = DEFAULT_WPPColumnTitle;

[Browsable(false)]
[WebPartStorage(Storage.Shared)]
public string WPPColumnTitle
{
    get { return this._WPPColumnTitle; }
    set { this._WPPColumnTitle = value; }
}

I always use the prefix "WPP" to keep all the web part properties together.

Then, in the Toolpart's ApplyChanges override, save the control's value (_ddlColumnsTitle) to the webpart (WPPColumnTitle):

/// <summary>
/// Called by the tool pane to apply property changes to
/// the selected Web Part.
/// </summary>
public override void ApplyChanges()
{
    // get our webpart and set it's properties
    MyCustomWebPart et = (MyCustomWebPart)ParentToolPane.SelectedWebPart;
    et.WPPColumnTitle = _ddlColumnsTitle.SelectedValue;
}

Lastly, if the user edited the properties already, we want the Toolpart to be pre-populated with the user's configuration. In the CreateChildControls() method of your Toolpart, initialize the controls:

protected override void CreateChildControls()
{
    try
    {
        MyCustomWebPart et = (MyCustomWebPart)ParentToolPane.SelectedWebPart;

        // ... code to create _ddlColumnsTitle and add it to the Controls

        // default our dropdown to the user's selection
        ListItem currentItem = _ddlColumnsTitle.Items.FindByValue(et.WPPColumnTitle);
        if (null != currentItem)
        {
            _ddlColumnsTitle.SelectedValue = currentItem.Value;
        }
    }
    catch (Exception ex)
    {
        _errorMessage = "Error adding edit controls. " + ex.ToString();
    }
}
懵少女 2024-10-10 04:09:41

打开调试器并仔细检查这些值是否已应用到您的“应用”属性(即设置了 WPPColumnTitle)。

如果是这样,那么问题是 SharePoint 不会将属性 (WPPColumnTitle) 中的值序列化/反序列化到数据库并返回 - 通过在 Web 部件上写出此属性进行验证 - 一旦您离开页面并返回,它就会被序列化/反序列化空的。

如果是这样,那么在类上检查类似的内容

[XmlRoot(Namespace = "YourNamespace")]

,在属性上检查类似的内容(不是绝对必要的)

[XmlElement(ElementName = "ColumnTitle")]

如果您将 Web 部件类命名为“WebPart”,因此将其称为 MyWebPart,我也会遇到问题

Open up the debugger and double check that the values are getting applied to your propertries on Apply (i.e. WPPColumnTitle is set).

If so then problem is that SharePoint is not serializing/deserializing the value from the property (WPPColumnTitle) to the database and back - verify by writing out this property on the web part - as soon as you leave the page and come back it will be empty.

If so then check things like this on class

[XmlRoot(Namespace = "YourNamespace")]

and this (not strictly necessary) on properties

[XmlElement(ElementName = "ColumnTitle")]

I've also seen problems if you name your web part class "WebPart" so call it MyWebPart

沫雨熙 2024-10-10 04:09:41

我通过在我的 web 部件“IsNeverSet”(布尔)中添加属性解决了这个问题
当我转到工具部分的“CreateControls()”时,我得到了这个属性
如果为 false,我会从 Web 部件加载所有属性并将它们填充到工具部件中。
所以我在 Kit Menke 的帮助下找到了它

I've solved it with adding a property in my webpart "IsNeverSet" (bool)
and when i go to the "CreateControls()" of my toolpart, I get this property
and if it's false, I load all the properties from my webpart and fill them in the toolpart.
So I found it with the help of Kit Menke

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文