Using Web Forms vs Windows Forms

R

Reds

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.
 
C

Cor Ligthert[MVP]

Reds,

What is new about that, why would somebody use winforms instead of webforms
as this was not as you wrote.

Webforms will allways use a kind of HTML and Javascript beside all kind of
other addons. It is a complete different technique to use. Although that
there have been and still is tried to evolt that to a situation were you can
develop for one and use only the winforms design.

Cor
 
P

Patrice

Keep in mind that a web form is created during the http request and then
deleted. Is is totally recreated for each new request (the idea is that as
we don't know if the user will ever ask something again to the server we
don't want to keep a fair amount of useless data for each user). So you
can't create a private member on a form and increment it. It will be lost
(as the form is created each time)

You'll have to read a bit more about how the web works. Try around :
http://msdn2.microsoft.com/en-us/library/y5y3c2c5(vs.71).aspx

For point #2 :
- doesn't work doesn't mean anything to us. What do you really see ? The
usual trap is to perfom something server side and thinking it works client
side or the other way round. It doesn't matter when the server and the
client is the same machine but once you are in a real world environment you
see it doesn't work anymore.
 
R

RobertW

Both previous posters were right about web forms.

They're basically HTML/Javascript pages (generated by ASP, but to the web
browser they're just HTML/Javascript) where the details are abstracted from
you so you can't see them. I honestly never liked (and never really spent
the time to learn) writing web pages ("web forms") with ASP.NET or even ASP
because I really didn't like the model. I prefer PHP for pages that run on a
web server, but that may be a little harder to code if you're just learning
the language and tools/libraries available for that.

Honestly, if you are targetting a specific customer or doing an in-house
project, I think the Visual Studio 2008 "WPF Browser App" (or called
something similar) which I'm now learning to use is so much nicer, and gives
you most of the functionality of the windows-based equivalent. I actually
host the WPF Browser app on my Linux-based (non-microsoft/windows) server and
the code on the server-side to access the database for me is PHP code -- only
the user interface is Microsoft-technology (.net 3.5).

The biggest problem with this approach, of course, is .net 3.5 is about a
30-minute installation- convincing my users to do this download may be
impractical, but once it's there, in theory, it's there for good. I'm hoping
Microsoft will eventually start forcing .net 3.5 on users via automatic
updates or better yet, a service pack. This will make my life easier in
terms of convincing my users to use the web app rather than download the
standalone .net 2.0 app which accesses the same database.

-Rob
 
L

Lloyd Sheen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top