Every single time your ASPX page loads (i.e. every HTTP request to the server) the page_load method runs. This happens before the button event handles. Here's what's happening:
Page Hit 1 (first plain page request)
-------------------------------------
Page Load
Load data reader
data reader.read()
Populate text boxes
Page hit 2 (click next)
-----------------------
Page Load
Load data reader
data reader.read()
Populate text boxes
Handle button click event
data reader.read()
populate text boxes
Page hit 3,4,5...n (click next)
-------------------------------
Page Load
Load data reader
data reader.read()
Populate text boxes
Handle button click event
data reader.read()
populate text boxes
The same exact thing is happening every time you click the next button regardless of how many times you clicked it.
Here's what I recommend:
Instead of a data reader, use a data adapter/dataset. The data reader is a connected data resource which is good for speed, but doesn't permit direct record access (go to record X). The data table in a dataset will allow you to hit DataTable(x).Row(n). The page load method can populate the dataset in place of the datareader.
Then you'll need to store the "current record" index to a page state variable. This is best done with the ViewState collection. You should set this on the first page load to 0, then work from there. The "next" and "previous" buttons can increment/decrement the record index accordingly. Put the few lines to populate the textboxes in another function so you can call it from all the places it will need to be used (page load, next, prev, etc).
-
Peter