• 0

[ASP.net] Data won't refresh


Question

I have an asp.net page written in VB that is designed to update information in a database. First the user views a page that holds the information. If they want to change it, they click on an edit button, which takes them to an edit page. Once the information is edited and the user clicks save, the information is written to the database (this works correctly) and then they are sent back to the first page to view the information. The problem is, when they are sent back to the first page, the information still reflects the 'before edit information' until you hit refresh. How can I combat this? I tried response.redirect("informationPage.aspx") but that still doesn't seem to solve the problem. Any help is appreciated. Thanks in advance,

Link to comment
https://www.neowin.net/forum/topic/145673-aspnet-data-wont-refresh/
Share on other sites

8 answers to this question

Recommended Posts

  • 0

It sounds like you are not binding the new data again. How is the data retrieved on the first page? Is it stored in a session object or something? If so make sure you reassign the new data there.

Also, on the first page, check the Load method. Make sure your logic is not messed up there. Posting en example of that function would help me out.

  • 0

Thanks for your help chorpeac. My page load sub is kind of long but here it is. Let me know if you have any questions. I really appreciate your help, this has been driving me crazy. I commented in the section that is not being refreshed. Thanks,

Sub Page_Load(Sender as Object, E as EventArgs)

Dim strID as string = Trim(Request.QueryString("ID"))

'Dim strrefresh as string = Trim(Request.QueryString("r"))

'data.refresh

'If not page.ispostback

'I was just playing with this trying to refresh the page

If strRefresh = "y" then

response.redirect("findingdetails.aspx?id=" & strID)

End If

'End If

If strID = "" then

response.redirect("default.aspx")

End If

'Make sure only authenticated users can use the page

If Session("loggedin") = false then

response.redirect("login.aspx?returnpath=findingdetails.aspx?ID=" & strID)

Else if Session("rights") = "" then

response.redirect("login.aspx?returnpath=findingdetails.aspx?ID=" & strID)

End If

storeID.text = strID

'-------------------------------------------------------------------------------------------

' Declare the database connection and connect to it

'-------------------------------------------------------------------------------------------

Dim strConnection As String = connString

Dim objConnection As New OleDbConnection(strConnection)

objConnection.Open()

Dim strSQLFindings as string = "Select FindingID, Find_Name, Find_Description, " & _

"Find_Quantification, Find_Justification, Find_DateSignedBy, Find_ManagerApproved, " & _

"Find_ManagerApprovedID, Find_ManagerApprovedDate, " & _

"Find_DateEntered, ImpactArea.IA_Name FROM finding, ImpactArea " & _

"WHERE finding.impactareaID = ImpactArea.impactAreaID AND finding.findingID = " & strID

'-----------------------------------------------------------------------------------

'Create a new instance of a data adapter.

'-----------------------------------------------------------------------------------

Dim objAdapter As OleDbDataAdapter = New OleDbDataAdapter(strSQLFindings, objConnection)

'test.text = strSQLFindings

'Exit Sub

'-----------------------------------------------------------------------------------

'Create a new dataset object and fill it with the data from the data adapter.

'-----------------------------------------------------------------------------------

Dim objDS As New DataSet

objAdapter.fill(objDS, "Findings")

'********************

'THESE ARE THE FIELDS THAT ARE NOT BEING REFRESHED

Dim strName as string = objDS.tables("Findings").Rows(0)("Find_Name").tostring

description.text = objDS.tables("Findings").Rows(0)("Find_Description").tostring

Quantification.text = objDS.tables("Findings").Rows(0)("Find_Quantification").tostring

Justification.text = objDS.tables("Findings").Rows(0)("Find_Justification").tostring

DateEntered.text = objDS.tables("Findings").Rows(0)("Find_DateEntered").tostring

ImpactArea.text = objDS.tables("Findings").Rows(0)("IA_Name").tostring

If not objDS.tables("Findings").Rows(0)("Find_DateSignedBy").tostring = "" then

Dim datsignedby as system.datetime = objDS.tables("Findings").Rows(0)("Find_DateSignedBy").tostring

datesignedby.text = datsignedby.tostring("MMMMMMMMMMMMMMM dd, yyyy")

Else

dateSignedBy.text = "Date not set"

End If

'********************

If objDS.tables("Findings").Rows(0)("Find_ManagerApproved") = true then

btnEYApprove.visible = false

'find the name of the manager that approved this finding

Dim strSQLManagerName as string = "Select User_FName, User_LName from [user] " & _

"WHERE UserID = " & objDS.tables("Findings").Rows(0)("Find_ManagerApprovedID").tostring

Dim objDSmID as new dataSet

Dim objAdapterMiD as OleDbDataAdapter = new OleDbDataAdapter(strSQLManagerName, objConnection)

objAdapterMiD.fill(objDSmID, "Manager")

Dim strManagerName as string = objDSmID.tables("Manager").Rows(0)("User_FName").tostring & _

" " & objDSmID.tables("Manager").Rows(0)("User_LName").tostring

lblEYApprove.visible = true

lblEYApprove.text = "This finding was approved by " & _

strManagerName & _

" on " & objDS.tables("Findings").Rows(0)("Find_ManagerApprovedDate").tostring & _

"."

End If

Dim strSQLSigners as string = "SELECT user.User_LName, user.User_FName, user.User_Email, " & _

"UserFinding.UF_SignedDate, UserFinding.UF_approved, UserFinding.UF_rejected " & _

"FROM [user], userFinding WHERE user.userid = userFinding.userID " & _

"AND userfinding.UF_Signer = true " & _

"AND userfinding.findingID = " & strID

Dim objAdapterSigners as OleDbDataAdapter = new OleDbDataAdapter(strSQLSigners, objConnection)

Dim objDSsigners as new DataSet

objAdapterSigners.fill(objDSsigners, "Signers")

Dim DCcheckSigned as dataColumn = new DataColumn()

DCcheckSigned.ColumnName = "Status"

objDSsigners.Tables("Signers").Columns.Add(DCcheckSigned)

Dim Srow as datarow

For each Srow in objDSsigners.tables("Signers").rows

If Srow("UF_Approved") = true then

Srow("Status") = "<img src=images/checked.gif height:10 width:12 />"

Else if Srow("UF_Rejected") = true then

Srow("Status") = "<img src=images/xed.gif />"

Else

Srow("Status") = "<img src=images/blank.gif />"

End If

Next

'this is not the part that I am having trouble with. This part works correctly.

DGStatus.datasource = objDSsigners

DGStatus.databind()

name.text = "<h2>Details for Finding " & strID & ":" & strName & "</h2>"

End Sub

  • 0

You do have a lot in your page load. Here is what my looks like when you edit an entry

Page load

      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            If Not IsPostBack Then
                LetsGetSomeData()
            End If
        End Sub

LetsGetSomeDate()

Public Sub LetsGetSomeData()
            Dim connWIF As New SqlConnection(ConfigurationSettings.AppSettings("MyConn"))
            Dim cmdLinks As New SqlCommand("SOME SQL STUFF", connWIF)
            Dim objDataReaderLinks As SqlDataReader
            connWIF.Open()
            objDataReaderLinks = cmdLinks.ExecuteReader(CommandBehavior.CloseConnection)
            DataGridEpisodeSchedule.DataSource = objDataReaderLinks
            DataGridEpisodeSchedule.DataBind()
            connWIF.Close()
        End Sub

Update the data sub

Sub DataGridEpisodeSchedule_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
            'Read in the values of the updated row
            Dim EpisodeScheduleID As Integer = e.Item.Cells(1).Text
            Dim EpisodeID As Integer = CType(e.Item.FindControl("DropDownList_Episodes"), DropDownList).SelectedValue
            Dim AirDate As DateTime = CType(e.Item.FindControl("TextBox_AirDate"), TextBox).Text

            Dim connWIF As New SqlConnection(ConfigurationSettings.AppSettings("MyConn"))
            Dim cmdLinks As New SqlCommand("Store procedure", connWIF)
            cmdLinks.CommandType = CommandType.StoredProcedure

            Dim parameterID As New SqlParameter("@ID", SqlDbType.Int, 4)
            parameterID.Value = ID
            cmdLinks.Parameters.Add(parameterID)

            connWIF.Open()
            cmdLinks.ExecuteNonQuery()
            connWIF.Close()

            'Finally, set the EditItemIndex to -1 and rebind the DataGrid
            DataGridEpisodeSchedule.EditItemIndex = -1
            LetsGetSomeData()
        End Sub

If you notice when I done storing the new values in to the database I call the LetsGetSomeData sub to reload the data. Hope it helps.

  • 0

I understand what you are saying in your code, but mine is a little bit different. I am doing the editing of the data on a completely different page. On this page, I am only displaying it. That is why it is baffling to me that it is not correct when the page is loaded for the first time after editing the data.

  • 0

I can't figure it out so I created a workaround solution. What I decided to to was rout to another arbitrary page (blank.aspx) and have that page rout back to the display page (displayData.aspx). This is not very efficient but it seems to be working fairly well. Thanks for all of your advice, guys. If you know of a better way to do this, then let me know.

  • 0

server.redirect is an ASP call. I think I heard something about using Server.Transfer now. If you want, try that and see if it helps.

I agree, your page_load is way to big. You need to learn to modularize that. That's why we have methods/functions/etc.

Since you said you have a solution, I'm not going to try to look through that long function right now.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • LG Electronics sees profit dip but boosts shareholder returns by Paul Hill LG Electronics (LGE) has reported consolidated sales of 20.74 trillion Korean Won (approximately $15.14 billion USD) and an operating profit of 639.4 billion Korean Won (approximately $466.75 million USD) for the second quarter of 2025. The firm saw both its revenue and operating profits decline year-over-year due to external factors such as US tariff policies, ongoing geopolitical issues in the Middle East, and a slowdown in consumer spending. While the company has faced challenges, the company is aiming for what it called qualitative growth by strengthening its subscription services, direct online sales, and business-to-business (B2B) segments. Key areas of growth for LGE include automotive electronics, heating, ventilation, and air conditioning (HVAC) systems, and the webOS platform. The US tariffs are a major headache for companies around the world, given the size of the market there and President Trump's demands for bringing manufacturing to the States. To combat the rising US tariffs, LGE is trying to optimize global production and refine its market-specific approaches for premium and mass-market products. While the company’s profits dipped, it announced an interim dividend of 500 Korean Won (approximately $0.37 USD) per share for both common and preferred, with another payout later in the year that should take the total for 2025 to at least 1,000 Korean Won (approximately $0.73 USD). You must be holding the stock on August 8, 2025, to get the payout on August 22, 2025. The firm also said it will cancel 761,427 common treasury shares on July 31, 2025, making shares more scarce which could increase the value of remaining shares for investors. In terms of LGE’s various business divisions, things were mixed. Its Home Appliance Solution (HS) business achieved year-over-year sales growth, maintaining profitability, thanks to a dual strategy for premium and volume segments and growth in online sales and subscriptions. Its Media Entertainment Solution (MS) business experienced declines in sales and operating profits with the latter turning negative due to market uncertainties and stiff competition. Its Vehicle Solution (VS) business showed growth in sales and operating profit thanks to increased orders from European automotive makers. Finally, its Eco Solution (ES) business saw domestic sales increase, but overseas sales growth was limited due to US tariffs. This led to a slight year-over-year drop in operating profit due to higher costs. Image via Depositphotos.com
    • "Microsoft plans to remove the MSN feed..." Yaaay, finally the horrible dumpster fire of badly translated tabloid trash is going away! Good riddance! "...and replace it with Copilot Discover..." Oh ffs...
    • Similar to how Nvidia stopped caring about the consumer market a while ago and now just pays lip service to it because it prints money.
    • Yep same as every company, sadly. The biggest bank in Australia just laid off a bunch of staff even though they made record profits, then advertised the roles in India
  • Recent Achievements

    • Week One Done
      Itbob513626 earned a badge
      Week One Done
    • One Month Later
      Itbob513626 earned a badge
      One Month Later
    • Rookie
      EdwardFranciscoVilla went up a rank
      Rookie
    • Week One Done
      MoJo624 earned a badge
      Week One Done
    • Collaborator
      aeganwn earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      618
    2. 2
      ATLien_0
      243
    3. 3
      Xenon
      159
    4. 4
      Michael Scrip
      126
    5. 5
      +FloatingFatMan
      122
  • Tell a friend

    Love Neowin? Tell a friend!