[SOLVED] LocalStorage.GetValue in vbnet?

Answered Closed
0
0

Hi,
how to use LocalStorage in vbnet (wisej 2)

Application.Browser.LocalStorage.GetValue(keyname, ???)

regards
Cristian

  • You must to post comments
Best Answer
0
0

Hi Cristian,

It would be something like this:

Private Sub Button1_Click()

        Application.Browser.LocalStorage.GetValue(Of String)("test", AddressOf ShowKeyValue)

End Sub

Private Sub ShowKeyValue(value As String)

        AlertBox.Show("Key Value was " + value)

End Sub

OR

Private Sub Button1_Click()
        Application.Browser.LocalStorage.GetValue(Of String)("test", (Sub(val As String)
                                                                           AlertBox.Show("Key Value was" + val)
                                                                      End Sub))
End Sub

OR

Private Async Sub GetValueAsync()
        Dim value as new Integer

        value = Await Application.Browser.LocalStorage.GetValueAsync(Of Integer)("test")

        ShowKeyValue(value)

End Sub

A few things:

  1. GetValue(of String) means that it is going to try to convert the value of the key/value to that specified type
  2. We need to define the callback, which is what the program will run after it has retrieved the requested value.
  3. AddressOf ShowKeyValue creates a delegate that points to the ShowKeyValue method
  4. ShowKeyValue takes one parameter (the value returned from the key/value lookup)

Let me know if you have any other questions!

Best,

Levie

  • You must to post comments
0
0

Hi Levie,
your code work perfectly.
but if I want to insert the value in a variable to be used immediately, isn’t it possible?
samething like

Dim pippo as string
Application.Browser.LocalStorage.GetValue(Of String)("test", (Sub(val As String)
pippo = val)
End Sub))
MessageBox.Show(pippo)

pippo in the messagebox is empty

  • Levie (ITG)
    Hi Cristian, I’ve updated my original answer to show you the solution using an asynchronous call. The reason you must use it one of these ways is is because GetValue() must make a call to the javascript in the browser and return the result to the server. If none of these solutions work for you and you don’t need to store your data on the client, it might be best to use the Application.Session object. Best, Levie
  • You must to post comments
Showing 2 results