Build Your Own ASP.NET 3.5 Website Using C# & VB (22 page)

Read Build Your Own ASP.NET 3.5 Website Using C# & VB Online

Authors: Cristian Darie,Zak Ruvalcaba,Wyatt Barnett

Tags: #C♯ (Computer program language), #Active server pages, #Programming Languages, #C#, #Web Page Design, #Computers, #Web site development, #internet programming, #General, #C? (Computer program language), #Internet, #Visual BASIC, #Microsoft Visual BASIC, #Application Development, #Microsoft .NET Framework

BOOK: Build Your Own ASP.NET 3.5 Website Using C# & VB
2.22Mb size Format: txt, pdf, ePub

to give feedback to the user.

HTML Server Controls in Action

Remember, HTML server controls are essentially HTML tags with the

runat="server" attribute. In most cases, you’ll also need to assign them IDs,

which will enable you to use the controls in your code.

Validation Warnings

You may notice that Visual Web Developer will display a validation warning

about the multiple=”true” attribute value on the select element. In XHTML

1.0, the select element only supports multiple=”multiple” and the IDE dutifully

reports the problem. However, since this is a server control—it has a

runat="server" attribute—you must specify multiple=”true”, otherwise the

page will not compile and execute.

When you eventually test this page, you’ll be happy to note that ASP.NET will

change the attribute value to multiple=”multiple” when the HTML is generated

and the page is displayed.

When it’s complete, and you view it in Visual Web Developer’s
Design
mode, the

Survey.aspx
web form will resemble Figure 4.1. Note that you can
’t execute the form yet, because it’s missing the button’s Click event handler that we’ve specified using

the OnServerClick attribute on the HtmlButton control.

Licensed to [email protected]

102

Build Your Own ASP.NET 3.5 Web Site Using C# & VB

Figure 4.1. A simple form that uses HTML server controls

When a user clicks on the
Confirm
button, we’ll display the submitted responses in

the browser. In a real application, we’d probably be more likely to save this information to a database, and perhaps show the results as a chart. Whatever the case, the code for the Click event handler method below shows how we’d access the properties of the HTML controls:
Visual Basic

LearningASP\VB\Survey_02.aspx
(excerpt)


C#

LearningASP\CS\Survey_02.aspx
(excerpt)


As with the examples we’ve seen in previous chapters, we start by placing our VB

and C# code inside a server-side script block within the