Sharepoint 自定义列表代码隐藏不在嵌入页面上调用
我在 sharepoint 中编写了一个自定义列表,其中 onPreRender 方法通过 Web 服务填充该列表。该列表每次呈现时都需要保持更新。当通过Lists->查看列表时MyList , allitems.aspx 被调用,我的代码(WebpartPage)被调用并更新列表。
但是,如果我将列表嵌入首页或其他任何地方,我后面的代码就不会被调用。它显示现有的列表数据。我做错了什么?
public class GetList: WebPartPage
{
protected override void OnPreRender(EventArgs e)
{
InvokeRefreshList();
base.OnPreRender(e);
}
private void InvokeRefreshList()
{
SPList myList = null;
SPWeb _web;
_web = SPControl.GetContextWeb(Context);
_webURL = _web.Url;
myList = SPContext.Current.List;
listTitle = myList .Title;
SPSecurity.CodeToRunElevated elevatedRefreshList =
new SPSecurity.CodeToRunElevated(RefreshList);
SPSecurity.RunWithElevatedPrivileges(elevatedRefreshList);
}
private RefreshList(){
//webservice code.
}
}
I have written a custom list in sharepoint, with the onPreRender method populating the list via a webservice. The list needs to stay updated everytime it is rendered. When the list is viewed via the Lists-> MyList , the allitems.aspx is called and my code behind (a WebpartPage) gets called and the list is updated.
But if i embed the list on the front page or anywhere else, my code behind does not get called. It shows the existing list data. What am i doing wrong?
public class GetList: WebPartPage
{
protected override void OnPreRender(EventArgs e)
{
InvokeRefreshList();
base.OnPreRender(e);
}
private void InvokeRefreshList()
{
SPList myList = null;
SPWeb _web;
_web = SPControl.GetContextWeb(Context);
_webURL = _web.Url;
myList = SPContext.Current.List;
listTitle = myList .Title;
SPSecurity.CodeToRunElevated elevatedRefreshList =
new SPSecurity.CodeToRunElevated(RefreshList);
SPSecurity.RunWithElevatedPrivileges(elevatedRefreshList);
}
private RefreshList(){
//webservice code.
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您要将列表放在主页(首页)中,我建议编写一个 WebPart 而不是 WebPartPage。因为当您将列表拖放到主页中时,您是间接放置 ListViewWebPart,而不是页面。所以很明显你的代码没有被调用。
Assuming that you are dropping the List in the Home Page (Front Page), I would suggest to write a WebPart not a WebPartPage. Because when you drop a list in the Home Page you are indirectly placing the ListViewWebPart, not the Page. So it is obvious that your code is not called.