Solved

viewstate issue with datagrid control on a modal window

Posted on 2006-11-13
9
337 Views
Last Modified: 2007-12-19
i have a main window that opens another window that has its own datagrid. when you add items in this modal window it will show up the changes but when you get out of the window because you made the chances or additions you wanted and then are back on that main menu. it will show the data in the grid normally when it loads but when u try to open the window again, it shows OLD data. on my page_load of the modal window the code is telling it to re load from the database. but i dunno, its connecting through the datagrid control databind
0
Comment
Question by:godcomputer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 9

Expert Comment

by:kraffay
ID: 17935046
What code do you have on page_load?
0
 

Author Comment

by:godcomputer
ID: 17935053
page_Load :
      LoadCategoriesData()

        If (Page.IsPostBack = False) Then
            BindDataGrid()
        Else

        End If


end page load


Private Sub LoadCategoriesData()
        '// Load data

        If IsNothing(ViewState("dsCategories")) Then
            Dim dsCategories As DataSet = New DataSet("dsCategories")

            'load main categories data
            Dim strSQL As String
            strSQL = "SELECT tblFileCategories.FileCategoryID, tblFileCategories.FileCategoryName, " & _
            "  tblFileCategories.FileCategoryDescription, tblFileCategories.CreatedDateTime, " & _
            "  tblFileCategories.CreatedByUser, tblFileCategories.ModifiedDateTime, tblFileCategories.ModifiedByUser" & _
            " FROM tblFileCategories " & _
            " ORDER BY tblFileCategories.FileCategoryName ASC"

            Dim SQLCn As SqlConnection = New SqlConnection(Cache("DBConnStr"))
            Dim SQLDA As SqlDataAdapter
            Dim SQLcmd As SqlCommand = New SqlCommand
            With SQLcmd
                .Connection = SQLCn
                .CommandType = CommandType.Text
                .CommandText = strSQL
            End With
            SQLDA = New SqlDataAdapter(SQLcmd)
            SQLDA.Fill(dsCategories, "tblFileCategories")

            'load dataset into viewstate


            ViewState("dsCategories") = dsCategories

            'cleanup
            dsCategories = Nothing
            SQLcmd.Dispose()
            SQLDA.Dispose()
            SQLDA = Nothing
            SQLCn.Dispose()
            SQLCn = Nothing
        End If
    End Sub

    Private Sub BindDataGrid()

        If Not IsNothing(ViewState("dsCategories")) Then
            If CType(ViewState("dsCategories"), DataSet).Tables("tblFileCategories").Rows.Count > 0 Then
                dgMaster.DataSource = CType(ViewState("dsCategories"), DataSet).Tables("tblFileCategories")
                dgMaster.DataBind()
                Dim intRowCount As Integer = CType(ViewState("dsCategories"), DataSet).Tables("tblFileCategories").Rows.Count
                Select Case intRowCount
                    Case 0
                        lblRecordCount.Text = "No Records Found"
                    Case 1
                        lblRecordCount.Text = intRowCount.ToString() + " Record Found"
                    Case Else
                        lblRecordCount.Text = intRowCount.ToString() + " Records Found"
                End Select
            Else
                lblRecordCount.Text = "No Records Found"
            End If
        End If
    End Sub
0
 
LVL 9

Expert Comment

by:kraffay
ID: 17935094
It looks like you load ViewState when you first get to the page:

           ViewState("dsCategories") = dsCategories

And then you check if the ViewState is loaded when you reload the page:

           If IsNothing(ViewState("dsCategories")) Then...

Theoretically, your ViewState should be lost when you close the pop-up.  But to be safe, I would only load the categories if you are not posting back:


        If (Page.IsPostBack = False) Then
            LoadCategoriesData()
            BindDataGrid()
        Else

        End If




0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:godcomputer
ID: 17935133
For some reason the old data shows up again when you click back into the modal window. whats wierd is, its showing me new stuff in the modal window when changes are made, then when u close out and get back in, the old data shows up. i did what you said and it wasnt the fix.
0
 
LVL 9

Expert Comment

by:kraffay
ID: 17935346
Is your browser caching the page?  Can you check you interner settings?
0
 

Author Comment

by:godcomputer
ID: 17935366
what setting do i check?

so does that mean if people have this feature on, that they will have to reset something EACH TIME? i think my problem is that its a modal window and its sending data back to to the parent window.

its type is
<base target="_self">
for the modal window.
so somehow its getting stuck
0
 
LVL 9

Expert Comment

by:kraffay
ID: 17935381
Which window is not getting refreshed, the parent or the pop-up?
0
 

Author Comment

by:godcomputer
ID: 17935388
pop-up
when u load it the 2nd time, its datagrid control has accient data, when u laoded the first time, yet when u goto close that window when u have made an update, it looks like everything has been changed ,then all of a sudden u revert back to the old view data the 2nd time.
0
 
LVL 29

Accepted Solution

by:
QPR earned 500 total points
ID: 17935668
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question