Solved

viewstate issue with datagrid control on a modal window

Posted on 2006-11-13
9
332 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
Comment Utility
What code do you have on page_load?
0
 

Author Comment

by:godcomputer
Comment Utility
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
Comment Utility
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
 

Author Comment

by:godcomputer
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 9

Expert Comment

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

Author Comment

by:godcomputer
Comment Utility
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
Comment Utility
Which window is not getting refreshed, the parent or the pop-up?
0
 

Author Comment

by:godcomputer
Comment Utility
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
Comment Utility
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now