[Gambas-user] variable in WebForm not remember

Rolf-Werner Eilert rwe-sse at ...3629...
Tue Jan 17 08:26:38 CET 2017


Am 16.01.2017 01:37, schrieb Benoît Minisini:
> Le 16/01/2017 à 01:20, מיוסט שרון a écrit :
>>>> hello
>>>>
>>>> I have WebForm1
>>>> I put on the WebForm1 two controls of WebButton1 WebButton2
>>>> I have a variable of type String named my_A
>>>> I would like when I press the WebButton1 the my_A = "sharon" and when I click on
>>>> WebButton2 I want to get the value found in my_A
>>>>
>>>>
>>>> The problem that when I click on WebButton2
>>>> The value of the variable my_A is empty ""
>>>>
>>>> It's what's inside that WebForm1.class
>>>>
>>>> ' Gambas class file
>>>>
>>>> Export
>>>> Private my_A As String
>>>>
>>>> Public Sub WebButton1_Click()
>>>>
>>>>    my_A = "sharon"
>>>>
>>>> End
>>>>
>>>> Public Sub WebButton2_Click()
>>>> 	
>>>>    WebButton2.Text = my_A
>>>>
>>>> End
>>>>
>>>
>>> Yes, this is the main difference between a "normal" application (one
>>> process that runs continuously) and a "webform" application (one process
>>> by request).
>>>
>>> With a web application, the only way to keep things persistent is using
>>> the Session object.
>>>
>>> With a WebForm, you can store permanent things by using it like an
>>> array, which use internally the Session object of course.
>>>
>>> So you can write:
>>>
>>> Export
>>>
>>> Public Sub WebButton1_Click()
>>>
>>>     Me["my_A"] = "sharon"
>>>
>>> End
>>>
>>> Public Sub WebButton2_Click()
>>> 	
>>>     WebButton2.Text = Me["my_A"]
>>>
>>> End
>>>
>>> So, never forget that your application is a web application that is not
>>> persistent between two events (the request is mostly the full handling
>>> of one event coming from the web browser. The response is the refresh of
>>> the web browser contents).
>>>
>>> Regards,
>>>
>>> --
>>> Benoît Minisini
>>
>>
>> Thank you it works
>>
>>
>>
>> I have another question that code:
>>
>> ' Gambas class file
>>
>> Export
>>
>> Public Sub WebButton1_Click()
>>    Dim hWeb As WebButton
>>
>>    WebButton1.Text = "btn1_text"
>>    WebButton1.Tag = "btn1_tag"
>>    Me["my_A"] = WebButton1
>>
>>    hweb = Me["my_A"]
>>    WebTextBox1.Text = hWeb.Text
>>    WebTextBox2.Text = hWeb.Tag
>> End
>>
>> Public Sub WebButton2_Click()
>>    Dim hWeb As WebButton
>>
>>    hWeb = Me["my_A"]
>>    WebTextBox1.Text = hWeb.Text
>>    WebTextBox2.Text = hWeb.Tag
>> End
>>
>>
>> WebButton1 the event of a hWeb this is fine value of WebButton1
>> But the event of WebButton2 value of hWeb get "NULL"
>>
>
> Not everything can be stored in the session. Especially object
> references (as they are valid only in the same process).
>
> You can put in a "WebForm variable" (i.e. Me[xxx]) : booleans, numbers,
> strings, dates, variant, arrays and collections.
>
> I hope I will be able to start writing the documentation of the
> gb.web.form component soon.
>
> Regards,
>

Where does the webform store the values until the next call? And can it 
remember calls from different users?

Regards
Rolf





More information about the User mailing list