I'm a VB.NET developer in training (still in college), and I'm working on my first ASP.NET web application. I'm extremely new to the concepts of ASP.NET and only know what I've read from a few chapters of a book.

That being said, I have a web form with 3 textboxes and 2 dropdownlists. When the page first loads, there is data that is pulled from a database and inserted into the textboxes and dropdownlists. I assign the data as follows:

textbox1.text = string1
dropdownlist1.selectedvalue = string2

so on and so forth.

The data in the textboxes and dropdownlists can be modified by the user. However, when I change the data in the textbox or the dropdownlist while the page is running and attempt to use the changed data in any other manner, it stays the same value as when the page first loaded.

I have tried two different scenarios. I have tried writing the modified data in the textboxes and dropdownlists to the database, and I have tried creating cookies with the modified data in the textboxes and dropdownlists. But the values stay the same as when the page first loaded.

if anyone can link me to a tip or offer some advice, I would greatly appreciate it. Thanks, Dave

below is my cookie code. I create when the user clicks a Save button. (i'm pretty sure the code is fine. however, the methodology may be all wrong)

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSave.Click
        Dim str As String = ""
        str = txtAso.Text & "|" & txtPer.Text & "|" & txtCat.Text & "|" & _
        ddlMonth.SelectedItem.Text & "|" & ddlYear.SelectedItem.Text & "|"
        Dim DataCookie As New HttpCookie("TMDBdata", str)
        Response.Cookies.Add(DataCookie)
        Response.Redirect("data.aspx")
    End Sub

    Private Sub LoadChanges()
        If Request.Cookies("TMDBdata") IsNot Nothing Then
            Dim str As String = Request.Cookies("TMDBdata").Value
            Dim count As Integer = 0
            Dim strChar As String = ""
            Dim strTmp As String = ""
            Dim strAso As String = ""
            Dim strPer As String = ""
            Dim strCat As String = ""
            Dim strMon As String = ""
            Dim strYer As String = ""
            Dim i As Integer
            For i = 0 To str.Length - 1
                strChar = str(i)
                If strChar.Equals("|") Then
                    count += 1
                End If
                If count = 0 Then
                    strAso &= strChar
                ElseIf count = 1 Then
                    strPer &= strChar
                ElseIf count = 2 Then
                    strCat &= strChar
                ElseIf count = 3 Then
                    strMon &= strChar
                ElseIf count = 4 Then
                    strYer &= strChar
                End If
            Next
            txtAso.Text = strAso.Replace("|", "")
            txtPer.Text = strPer.Replace("|", "")
            txtCat.Text = strCat.Replace("|", "")
            ddlMonth.SelectedValue = strMon.Replace("|", "")
            ddlYear.SelectedValue = strYer.Replace("|", "")
        End If
    End Sub

After pulling my hair out for a couple days thinking about this (I took a break from writing code and decided to just think about it), the solution was extremely simple.

All I had to do was assign the strings to the textboxes in the Page_LoadComplete event, and that fixed it entirely.

(It's funny, I always seem to solve my own posts, no one seems to reply to any of them. I guess no one likes me ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.