Page VIEWSTATE
The other change is that ASP+ has automatically added a HIDDEN-type
control to the form:
This is how ASP+ can store ambient state changes of a page across multiple
requests – i.e. things that don't automatically get sent back and forth between
the browser and server between Web requests. For example, if the background
color of a server control had been modified it would use the VIEWSTATE
hidden field to remember this between requests. The VIEWSTATE
field is used whenever you post back to the originating page. In Chapter 2,
we discuss this topic in more detail.
So,
as you can see, there really aren't any 'magic tricks' being played. It's
all standard HTML, with no client-side script libraries, and no
ActiveX controls or Java applets. An equally important point is that absolutelynostate is being stored on the server. Instead, values are
simply posted to the server using standard methods. Values are preserved and
maintained across requests simply by the server controls modifying the HTML
before the pages are sent to the client.
Server-side Code in ASP+
To display the values in the page, we used code that is very similar to that
we used in the ASP example earlier on:
...
If Len(Request.Form("selOpSys")) > 0 Then
strOpSys = Request.Form("selOpSys")
strName = Request.Form("txtName")
Response.Write("You selected '" & strOpSys _
& "' for machine '" & strName & "'.")
End If
...
However, one of the other great features of ASP+ and server controls is that
they are available to the code running on the server that is creating the page
output. The ASP+ interpreter insists that each one has a unique id
attribute, and therefore all the server controls (i.e. the elements that
have the runat="server"
attribute) will be available to code against. This means that we no longer have
to access the Request
collection to get the values that were posted back to the server from our form
controls – we can instead refer to them directly using their unique id:
...
If Len(selOpSys.value) > 0 Then
Response.Write("You selected '" & selOpSys.value _
& "' for machine '" & txtName.value &
"'.")
End If
...
Visual Basic Code in ASP+
In the ASP page we've just seen, the script was assumed to be VBScript (we
didn't specify this, and VBScript is the default unless you change the server
settings). In ASP+, there is no support for VBScript. Instead, the default language
is Visual Basic ("VB"), which is a superset
of VBScript. So, our code is being compiled into IL and executed by the runtime.
The compiler and runtime for Visual Basic that is included with ASP+ is the
new version 7.0 (good news – you don't need to buy a separate copy!). There
are a few implications in this, which we summarize in Appendix B
of this book.
The most important thing to note straight away is that all method calls in
VB7 must have the parameter list enclosed in parentheses (much like JScript
and JavaScript). In VBScript and earlier versions of VB, this was not required
– and in some cases produced an error. You can see that we've enclosed the parameter
to the Response.Write
method in parentheses in our example.
Secondly, VB7 has no concept of 'default' methods or 'default' properties,
so we now must provide the method or property name. You'll probably come across
this first when working with ADO recordsets where the syntax must be:
fieldvalue = objRecordset.Fields("fieldname").value