asp.netlistviewpaginationdatapager

Why does DataPager need Pre-Render event to work??


Having to use pre render is causing me problems.. It would be great if I did not need it.. The problem is I have the list in a user control and when I goto the next 'page' I databind.. but then the datapager prerenders.. which also does a batabind.. so it runs twice..

If I remove the prerender .. then clicking next 'page' does nothing..

Any idea?

   protected void Page_Load(object sender, EventArgs e)
{
    GetSearchResults();
}

//protected void dpMembers_PreRender(object sender, EventArgs e)
//{
//    GetSearchResults();
//}

public void GetSearchResults()
{
    List<Person> listPerson = new List<Person>();
    string strServer = "localhost";
    string strAppPath = Server.MapPath("/");
    PersonBusiness pb = new PersonBusiness(new PersonRepository());
    listPerson = pb.GetAllPersons(strServer, strAppPath);
    lvPersons.DataSource = listPerson;
    lvPersons.DataBind();
}

Solution

  • Modify your Page load to

    protected void Page_Load(object sender, EventArgs e) { if(!Page.IsPostBack) { GetSearchResults(); } }

    your prerender seems ok.