Sharepoint 自定义列表代码隐藏不在嵌入页面上调用

发布于 2024-08-24 00:44:41 字数 903 浏览 7 评论 0原文

我在 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 技术交流群。

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

发布评论

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

评论(1

逆光下的微笑 2024-08-31 00:44:41

假设您要将列表放在主页(首页)中,我建议编写一个 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.

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