Reds said:
HI,
I have just started using Web Forms. It seems that I'm not able to do
some things that Windows Forms allow me to do. For example, I tried to
implement a counter using a module level declaration, but it would not
increment using Web Forms.
Also, some controls such as textboxes, which worked OK on the computer,
did not work when I placed the project on the server and accesed it via
the internet.
Welcome to the wonderful world of ASP.NET.
First off when you have questions about ASP.NET I would suggest you post
them to the microsoft.public.dotnet.framework.aspnet newsgroup. They are
more likely to know what you are asking since most of the question will be
about ASP rather than VB.
What you saw is the first thing to learn about ASP.NET. The net is
stateless. This means that without you doing something to save the
information between posts it will be lost.
The second as stated in other posts here is that regular windows controls
are not used in web pages. When you look at the toolbar in either VWD or VS
you will see the web controls. There is not a one to one from web to
windows forms.
Now as a starter lets look at what you did (my supposition).
Lets say you create a web page with a label and a button. You have a
variable to hold the count and each time you click the button you want the
count to increment and you will show the new total on the label. As you saw
when you get the button click the variable is set to whatever you set it to
be in the declaration.
dim _total as integer = 0.
That will ensure that each time you get the button click event the variable
total will be zero. How do you get around this? There is a mechanism
called Session which can hold the information you want save between
postings. It is a simple dictionary so when you go to the click event the
code would look something like:
if session("total") isnot nothing then
_total = session("total")
end if
What this does is see if the session variable ("total") has been set up. If
not you are on your first go around. If this is a postback will then return
the value you saved (in a minute) and you can then increment the _total
variable and save it back to the session.
_total +=1
session("total") = _total
This is a very simplified example. I would suggest the first thing you
investigate is what is called the life cycle of an asp.net page. Without
knowing this you will most likely spend a lot of time scratching your head
about what has happened.
Now go to
http://www.asp.net/learn/videos/
There are about 50 video tutorials on this page. I spent the time and it
was well worth it. Without those videos I might not have any hair left.
Good luck
Lloyd Sheen