Max,
A webform life cycle is very different from a windows form one. A windows
form stays in the memory all the time. A webform's life is very short - from
the http request arrival to sending the response back. A few seconds or
less. After the page has been served to the client, there is nothing left
from the page in the server's memory unless you take a special care to
persist what you may need in feature requests.
In your case the page first makes a request (postback) to serve the server
event Button1_Click. The response is sent and the page's gone. Then another
request arrives, this time for the server event Button2_Click. At this stage
nothing is left on the server from the previous request. The page builds
from scratch with s As String ''''.
To use s in the second postback, you need to persist it. There are several
ways of doing this, most common are in a session variable and in ViewState.
Make your research on the differences.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Max" <ma******************@fastwebnet.itwrote in message
news:JE*****************@tornado.fastwebnet.it...
I 've got to understand this. I come from dotnet windows applications, not
webforms, ok, but this is too strange and I've already asked this NG and
tried what suggested without solution
Why this doesn't work: I press Button1 and the textbox shows "hello" -
then
I press button2 and textbox shows empty field!
What else to do, everything is public here.
Please help
Max
Public Class Default5
Inherits System.Web.UI.Page
Public s As String ''''(or Dim s as string, it's the same)
''''''''''''''''''''''
Public Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
s = "hello"
TextBox1.Text = s
End Sub
'''''''''''''''''''''''''
Public Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text = s
End Sub
end class