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

Ronald
  • 1,990
  • 6
  • 24
  • 39

2 Answers2

0

Could you not simply manually page?

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

Jammin
  • 3,050
  • 2
  • 23
  • 34
  • 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 – Ronald Apr 15 '10 at 17:01
0

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
  • 11,489
  • 9
  • 73
  • 80
  • 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. – Ronald Apr 20 '10 at 16:56