Solved

viewstate issue with datagrid control on a modal window

Posted on 2006-11-13
9
339 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

617 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