문제

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.
    }
}

올바른 솔루션이 없습니다

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top