views:

207

answers:

1

I've created a Web User Control that is placed on the page at design time. It's purpose is to pop up with a grid of items the user is to choose from. So I've got a gridview on it. And this code in the usercontrol:

    Public Property DataTable() As Data.DataTable
    Get
        If Not IsNothing(ViewState("_SelectGridDataTable")) Then
            Return ViewState("_SelectGridDataTable")
        Else
            Return Nothing
        End If
    End Get
    Set(ByVal value As Data.DataTable)
        ViewState("_SelectGridDataTable") = value
    End Set
End Property

So when the user clicks on a button on the page, I put this in the code on the page:

SelectGrid2.DataTable = GetContacts().Tables(0)
SelectGrid2.Show()

And this works fine. The grid pops up (using jQuery) and the grid is shown. The problem is, that when the user clicks the "OK" button on the UserControl, the ViewState("_SelectGridDataTable") is always nothing. And I don't get it, since it's in the viewstate.. ?!? So does viewstate here not REALLY mean viewstate?

A: 

Oops. I didn't realize the viewstate doesn't exist during the Page_Init. I moved my check for the datatable to the page load, and now it works. Thanks @Michel for giving me the idea to check that..

Dan