Hello, I have a website that does calculations. I have a textbox that shows the results. I also have a button, and when I click this button I want it to add the results from the textbox into the array. I then have another button and I want to print the items that I have saved to the array on the screen. This is what I have and it is not working:

<script runat="server">
     Dim MyArray(9) As String
    Dim i As Integer

Protected Sub storedataButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        
        For i = 0 To 9
            MyArray(i) = resultTextBox.Text
        Next i
    End Sub

    Protected Sub printdataButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        For i = 0 To 9
            Response.Write("Result " & i & " is" & " " & MyArray(i) + "<br />")
        Next i
    End Sub
</script>

Can somebody tell me what I am doing wrong, please? I am still kind of new to all of programming. Maybe somebody can give me a better idea of how I can do this???

Thank you

Http is a stateless protocol. When you submit a page ASP.NET intercept the HTTP request and create a new page object - so, fields and control are created each time when a page is postback (submitted).

Solution of this problem is to use State Management - ViewState, Session, Cookies, Cache, Application etc. At this point I am suggesting to use Session or ViewState object.

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.