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