Solved

viewstate issue with datagrid control on a modal window

Posted on 2006-11-13
9
338 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

752 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