Really weird... So I'm trying to save the page index of my gridview in a Session Variable and then reset the index when the user navigates back to the gridView. Here's my code below;

```
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs)
    If Not Page.IsPostBack Then
        If Not Session("CurrentPage") Is Nothing AndAlso 
Session("CurrentPage") <= GridView1.PageCount Then
            GridView1.PageIndex = Session("CurrentPage")
        End If
    End If
End Sub

```

Well the weird thing is that when I breakpoint on the second IF above and hover over pageCount it says it's 0. If I then go into my watch window and look at it (0 once again), then go back to my code and hover again it's 2 (which it should be)! I can then Continue past the break point and the page displays on page 2 as it should. However, and this is where it gets really weird, if I remove the breakpoint and run it I end up on page 1! So it's as if the `PageCount` hasn't updated unless I've put a breakpoint on it and specifically looked at it. Anyone explain this behaviour and how to get around it?!

**UPDATE**

Here's a pic of the values of the variables in question. You can see the PageIndex wasn't updated because it never entered the `IF` statement because moments earlier the PageCount was 0!! I can't be the only one stumped by this :/

Image of variable values: ![enter image description here](https://i.stack.imgur.com/50d2r.png)