Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

viewstate issue with datagrid control on a modal window

Posted on 2006-11-13
9
Medium Priority
?
341 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 2000 total points
ID: 17935668
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

926 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