Home > Articles

Building the User Interface with Web Forms

Web applications are becoming more and more important, and Web Forms make creating them incredibly easy. Learn how to use the tools in Visual Basic.NET to create web pages that provide fairly rich user interfaces across any browser.
This chapter is from Sams Teach Yourself Visual Basic.NET in 21 Days.

While most traditional applications used the Windows Forms model, creating Web or browser applications continues to become more and more important. Today, we will look at how we can create browser-based user interfaces. The tools within Visual Basic.NET assist the developer in easily creating web pages that provide fairly rich user interfaces across any browser type. In particular, today we will focus on:

  • How the web programming model differs from the traditional Windows based model

  • Using standard Web Forms controls

  • Using advanced Web Forms controls

  • Using the Validator controls

The Web Programming Model

Some days I think that everyone in the world is on the Internet, especially when my access speed is in the painfully slow mode as everyone is browsing, chatting and e-mailing (but not doing business). (As a tip, I somehow find that the best time to be online is during Star Trek – probably just a coincidence). Obviously, one of the most important, or at least popular, tools aspects of the Internet is the World Wide Web (WWW). However, there has generally been a shortage of really good programming tools for creating WWW 'programs', rather than just simple WWW pages. This is at least partly because creating applications for the Web is different from creating applications for a desktop computer, where you have more control. In addition, web applications must deal with the network more frequently.

So, what is the "Web Programming model"? It is just a term used to describe how you can design, or architect, a program that uses web pages in a browser as a way to allow the user to enter information. These web pages are designed using HTML (HyperText Markup Language – we won't be covering HTML in this book, but there are plenty on the market). The browser is an application that knows how to read HTML and display it on the screen. Usually (but not always), most of the work of the application is done on the web server. The Web Server is another program running on a computer that knows how to return HTML on demand. In Windows NT and 2000, this program is called Internet Information Server (IIS). The information is carried between the browser and the server using a protocol, or language, called HTTP (HyperText Transfer Protocol).

NOTE

The actual name of IIS has changed with the different versions. In Windows NT 4.0 Server, it is called Internet Information Server. In Windows 2000, it is called Internet Information Services, while in Windows NT 4.0 Professional it is Personal Web Server.

In the 'beginning' of the World Wide Web, web pages were static. That is, they never really changed. Things got more interesting when people started to create dynamic, or changing, web pages. This was the dawn of the 'Web Program'. With 'Web programs', rather than simply returning the same HTML every time, the web server may perform some task and return HTML appropriate to the result. For example, the user might request the sales information for a particular date range. This information is passed to the server. The server in turn might look that information up in a database, and then write the HTML to display it to the user. The whole process looks similar to Figure 10.1.

Figure 10.1 Web programming model.

Alternately, the server (or web page designer) might add programming information to the page itself, creating a page that is a little program in its own right. This is often called Dynamic HTML (or DHTML). With DHTML, the page includes some JavaScript (a programming language, like Visual Basic.NET that runs in web pages) or other language. The code can run in thepage then runs this codebrowser, which can update the page without needing to send any information back to the server. Figure 10.2 shows this model in action.

Figure 10.2 Dynamic HTML programming model.

There are a variety of techniques that can be used to create a web program. Some of the most common techniques used in the past have been ASP (Active Server Pages), Perl (another programming language) or JSP (Java Server Pages). The technique used by Web Forms is an improvement of ASP, ASP.NET.

ASP.NET

ASP.NET is Microsoft's name for its improved version of ASP. While ASP was a very easy method for building dynamic web pages, it had some problems that ASP.NET is designed to solve:

  • ASP often required too much code to get something done. ASP.NET requires less code (often much less code) for common programming tasks.

  • ASP still suffered from the limited number of controls that HTML suffers from. ASP.NET adds the idea of "server-side controls" that can generate HTML appropriate to the browser requesting it. While these controls are just HTML in the browser, they can represent a great deal of HTML and code, saving you from _having to write it.

  • ASP only allows you to program in a language such as VBScript. VBScript is interpreted at run time, not compiled like real Visual Basic. ASP.NET allows you to write their web pages in real, fully compiled Visual Basic.NET.

ASP.NET is also designed to solve other problems with ASP that aren't appropriate to our discussion of building user interfaces, such as improvements to scalability and memory use. There should be a few good books available specifically on ASP.NET by the time you read this.

How Creating Web-based Programs is different from Creating Windows-based Programs

When you are designing a Web-based program using WebForms, there are a number of differences you must keep in mind. Some of the differences include:

  • Web-based applications tend to have more code on the server, rather than the client. That is, the 'look and feel' of your program is in the browser, but the smarts are on the server.

  • Web-based applications are dependant on the capabilities of the browser used to view them. Sadly, each browser has different capabilities, and many web developers have had to struggle with these differences as they designed their programs.

  • Once you receive the web page, it tends to be static. While there are ways you can update the page without returning to the server (that is, to make it dynamic), these make creating the page more complex. Therefore, animated forms (or any kind of responding to the user) are more difficult with web-based applications.

  • Many operations of a web-based application require a "network round-trip". This is due to the separation of code and design. In order to have a button or other control do something, it is often necessary to send information to the server. The server then responds as appropriate. You should keep this in mind when you are creating web applications. This back and forth communication might take a while, so you should only do it as necessary.

Web-based applications are limited, both by the limitations on the browser itself, and on the number of browsers in useavailable on the market. Browsers are limited in the type of controls that can be used, as well as by their limited drawing capabilities. In addition, if the user has installed an older version of a browser, or has disabled certain features, the web page may react in different ways. This is one of the main reasons that web-based applications tend to place most of the code on the server. In addition, this has meant that traditionally web-based applications have required a lot of code to be added to change the appearance of the web page based on the browser viewing it. Fortunately, the WebForm controls hide most of those details from you. They are written to produce dynamic output (that is, the page can change without needing to send information back to the server) if they detect the browser is capable of using it. If they do not recognize the browser being used, or if the browser would not support dynamic updating, only plain HTML is returned to the client browser. This ensures the developer that the client browser will receive the web page designed, within the limitations of the browser.

In addition to the limits caused by the browser, web-based applications also require the developer consider the fact that the client and server are separated, possibly by great_ distances by a network. This means that operations that might only take a few seconds_ if the client and server are close (or even the same machine) could take a long time. _So, operations like animations might be jerky, or not display at all until the download is completed. Also, the speed of the connection comes into play. If you are accessing the web page using a slower modem this difference is made even more significant.

With all these issues to keep in mind, you might ask 'Why bother creating web applications'? While there is a downside to creating web applications, there are many benefits:

  • Installation in order to make your application available, all you need to do is point someone at the URL. The application is immediately usable by the client. This saves you from having to visit each of those client machines, or from having your users all install the application.

  • New Versions and/or bug fixes when you want to upgrade to a newer version of part of your application, you only need to install the upgrades at the server, not at every client.

  • Performance the answers to how to improve performance of web applications are much easier than those for regular applications. You can improve performance by adding more servers, and distributing the requests across all the servers.

  • Knowledge if you already know some HTML, Web Applications can be much easier than Windows Applications. Alternately, they can be easier to learn if you know neither.

So, when designing an application, should you create a Windows-based or Web-based program? The easy (but unsatisfying) answer is, "It depends". Many applications fit either type, but more and more often, people are starting to create more Web-based applications. The ability to easily make upgrades and fixes available is compelling, so you might want to at least consider creating your programs as Web applications first.

Some applications are not candidates for Web applications, however. Any programs that require a continuous link between client and server are not appropriate, nor applications that require a lot of graphics (like games). Finally, if you only have a single computer involved (that is, not a client-server application like a database program), or if it is only for yourself, it may make sense to create a Windows-based application.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020