views:

1945

answers:

6

I have a search page with parameters at the top and a search button with results at the bottom. The entire thing is wrapped in an update panel inside the master page. After clicking the search button it shows the first page. However if you click the next button on the DataPager it does not show the second page. It shows no results for the second page. Any help would be greatly appreciated.

A: 

Please make sure that your page change event is registered with the Script Manager as it is out of the update panel control. ScriptManager.RegisterAsyncPostBackControl(DatePager Control);

Sachin Gaur
A: 

Sachin,

Thanks for the quick response. I tried registering the DataPager as a AsyncPostBackControl and also as a PostBackControl. Still the same issue.

    Dim mgr As ScriptManager
    mgr = CType(Master.FindControl("ScriptManager1"), ScriptManager)
    mgr.RegisterAsyncPostBackControl(Pager)
Greg Finzer
A: 

At the bottom of your update pannel do this:

       <Triggers>
                                <asp:PostBackTrigger ControlID="DataPager1" />
                            </Triggers>
                    </asp:UpdatePanel>
Jojo
+1  A: 

It sounds like your control isn't binding in the postback, which event are you doing the DataBind() in, and is it under an

if(!IsPostBack) { }

wrapper of some sort?

Nick Craver
+1  A: 

I think Nick has the right idea. It sounds like you are performing your search and populating your ListView in your OnClick method for your search button. You need to perform your search (or preferably cache the data the first time around) and bind that to the ListView for each new page that is requested using the DataPager.

You can do this fairly easily by creating a method for the ListView's OnPagePropertiesChanged event. Perform the search (or pull from the cache) and bind the ListView in that OnPagePropertiesChanged event and your data should populate. Your C# code might look like this:

protected void SearchButton_OnClick(object sender, EventArgs e)
{
    PerformSearch();
}

protected void PerformSearch()
{
    // ...Get your data.... //

    ListView1.DataSource = data;
    ListView1.DataBind();
}

protected void ListView1_OnPagePropertiesChanged(object sender, EventArgs e)
{
    PerformSearch();
}
Austin
had the exact same problem as the OP, added the PagePropertiesChanged event handler and that fixed it.
derek
A: 

I had a similar problem when using a DataPager on a data control where EnableViewState=false.

Even Mien