0

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

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by __avd
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.