Sharepoint Custom List code-behind not invoked on a embedded page

816 views Asked by At

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

There are 1 answers

0
Kusek On

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.