gpt4 book ai didi

asp.net - SharePoint Web 部件自定义属性在页面重新加载后才会生效

转载 作者:行者123 更新时间:2023-12-01 19:27:26 25 4
gpt4 key购买 nike

我正在开发一个使用自定义属性的 sharepoint 2007 Web 部件。这是其中之一:

[Personalizable(PersonalizationScope.User), WebDisplayName("Policy Update List Name")]
[WebDescription("The name of the SharePoint List that records all the policy updates.\n Default value is Policy Updates Record.")]
public string PolicyUpdateLogName
{
get { return _PolicyUpdateLogName == null ? "Policy Updates Record" : _PolicyUpdateLogName; }

set { _PolicyUpdateLogName = value; }
}

这些属性工作正常,只是更改不会反射(reflect)在 Web 部件中,直到您离开页面并导航回来(或仅单击主页链接)。单纯刷新页面是不行的,这让我觉得这和PostBacks有关。

我目前的理论是 ViewState 没有足够早地加载回发数据以使更改生效。至少,ViewState 在某种程度上与这个问题有关。

谢谢,迈克尔

这里是更相关的代码:

protected override void CreateChildControls()
{
InitGlobalVariables();

FetchPolicyUpdateLog_SPList();

// This function returns true if the settings are formatted correctly
if (CheckWebPartSettingsIntegrity())
{
InitListBoxControls();

InitLayoutTable();

this.Controls.Add(layoutTable);

LoadPoliciesListBox();
}

base.CreateChildControls();
}

...

protected void InitGlobalVariables()
{
this.Title = "Employee Activity Tracker for " + PolicyUpdateLogName;

policyColumnHeader = new Literal();
confirmedColumnHeader = new Literal();
pendingColumnHeader = new Literal();

employeesForPolicy = new List<SPUser>();
confirmedEmployees = new List<SPUser>();
pendingEmployees = new List<SPUser>();
}

...

// uses the PolicyUpdateLogName custom property to load that List from Sharepoint
private void FetchPolicyUpdateLog_SPList()
{
site = new SPSite(siteURL);
policyUpdateLog_SPList = site.OpenWeb().GetList("/Lists/" + PolicyUpdateLogName);
}

...

protected void InitListBoxControls()
{
// Init ListBoxes
policies_ListBox = new ListBox(); // This box stores the policies from the List we loaded from SharePoint
confirmedEmployees_ListBox = new ListBox();
pendingEmployees_ListBox = new ListBox();

// Postback & ViewState
policies_ListBox.AutoPostBack = true;
policies_ListBox.SelectedIndexChanged += new EventHandler(OnSelectedPolicyChanged);
confirmedEmployees_ListBox.EnableViewState = false;
pendingEmployees_ListBox.EnableViewState = false;
}

...

private void LoadPoliciesListBox()
{
foreach (SPListItem policyUpdate in policyUpdateLog_SPList.Items)
{
// Checking for duplicates before adding.
bool itemExists = false;

foreach (ListItem item in policies_ListBox.Items)

if (item.Text.Equals(policyUpdate.Title))
{
itemExists = true;
break;
}
if (!itemExists)
policies_ListBox.Items.Add(new ListItem(policyUpdate.Title));
}
}

最佳答案

阅读有关 Sharepoint Web 部件生命周期的内容。在 OnPreRender 事件发生之前,属性不会更新。

关于asp.net - SharePoint Web 部件自定义属性在页面重新加载后才会生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6685556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com