Hi all,
My first time here. I'm quite the newbie when it comes to ASP after coding in VB6.
Frankly I'm stumped by something I'm sure should have a simple solution. Here's a very basic snippet of what I'm trying to do, so the problem (and hopefully the solution) is clear:

Partial Class _Default
    Inherits System.Web.UI.Page
    Public this As New Dictionary(Of Integer, String)

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        this.Add(1, "This works")
    End Sub

    Private Sub Create_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Create.Click
        this.Add(2, "This doesn't work")
    End Sub

    Private Sub Show_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Show.Click
    End Sub
End Class

Is there an efficient way of using one button to pull in some data, then use another button to do something with it? It seems that anything I do within the button's procedure clears as soon as I come out of it.

Should I use something like a placeholder to put my dictionary into and access it that way? Or is that an inefficient way of dealing with this?

Any help greatly appreciated.

7 Years
Discussion Span
Last Post by Paradox 99

each time a page is loaded, the code above runs. You are recreating the dictionary object upon postback (postback occurs when you click on a button). You need either store the object in a session variable if you need to use this object in various pages, or else store it in ViewState if you intend to use the object in the same web form.

If this was useful, please mark this post as solved


Thank you so much!
I'm not sure I know how to use a session variable yet, or if it's the appropriate way to go, but the explanation of what's happening is very useful. Marked as resolved.

Thanks again. :)

This question has already been answered. 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.