views:

114

answers:

2

I'm using a datapager control on my listview to perform paging in it.

When paging through the table, I need to perform some validations. When these validations are not successfull, the paging should be cancelled.

I currently perform the validation in the PagePropertiesChanging event of the ListView, however, the arguments do not provide a Cancel property.

protected void MyListView_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
     if (!Validate())
     { // cancel the paging action}
} 

Does anyone know if canceling the paging is possible and how to perform it? Thanks

A: 

Could you not simply manually page?

Eg Validate then page if OK, as opposed to try and page, validate, then cancel.

Jammin
yes, but i was wondering if it was possible with the build-in pager controls. i was able to implement the next/previous using the TemplatePagerField and its PagerCommand, but am not able to replicate the NumericPagerField
Littlefool
A: 

I too was disappointed to find there was no simpler way to do this. I ended up very much like Littlefool, where I made use of the PagePropertiesChanging event. In it, if my validation did not pass, I called the SetPageProperties() on my DataPager with a saved off value of its previous StartRowIndex value, which I save off in the ViewState.

Not my proudest solution but it works.

Tyler Collier
yes, this seems like the "only" way. I ended up with implementing the next/previous using the TemplatePagerField. Once they complain about the numeric paging, i'll do it this way.
Littlefool