Request.Form(Object).OptionalIndex.Count The object you need to access can be entered as the Object part. For example, you can enter the name of a form's control as "Object". This can be done as follows: Request.Form("txtFirstName")
In our lessons about arrays and collections, we will review what roles the OptionalIndex factor and the Count value play. For now, we will ignore them.
Besides, or as opposed to, collecting values using the controls on a form, you can request a string. To support this, the Request object is equipped with QueryString, which also is a collection. This allows you to get values either from a control or directly from the address bar of the browser. Remember, the GET value of the METHOD attribute of a form causes its information to be displayed in the address bar of the browser when that information is being sent: Notice that the section on the right side of the question mark includes parts using the formula Name=Value. This indicates that the section on the right side of the question mark is in fact a collection of strings. Each string in this collection can be produced to you by Request.QueryString. The syntax of Request.QueryString is: Request.QueryString(Variable).OptionalIndex.Count The Variable parameter is the name of the string that you want to retrieve. It can be the name of a control passed as argument. Here is an example: Request.QueryString("txtFirstName")
It can also be the name of a variable. In our lessons about arrays and collections, we will review what roles the OptionalIndex factor and the Count value play. This also means that, as opposed to the Request.Form collection that uses the POST value of the method attribute of a form, when using the Request.QueryString property, you should send values using GET.
Although most web pages are meant only to display values, some others, mostly interactive pages, allow a visitor to submit values. To do this, a visitor may type in a text box, select a radio button, or click a check box. These actions create a value on the browser. The browser is referred to as a client because this is where the visitor creates a value. After formulating a value, a user would click a button to send the value to you. You get that value on the server. To assist you with getting a value from a browser, the .NET Framework provides a class named HttpUtility.
When a web page visitor types a value or selects from a control, the value must be analyzed and made into a readable type. To make this possible, the value must be encoded. To support this operation, the HttpUtility class is equipped with a method named HtmlEncode. The value must be passed in the parentheses of HttpUtility.HtmlEncode(). This value would be the one you get from a call to Request.QueryString(ControlName). This means that you can pass the Request.QueryString(ControlName) expression to the HttpUtility.HtmlEncode() call. This would be done as follows: <%@ Page Language="C#" %>
<html>
<head>
<style>
body {
font-family: Verdana, Helvetica, Arial, 'Sans Serif';
color: #000000;
font-size: 10pt;
background-color: #FFFFFF }
hr { color=#000080 }
.toptitle {
color: #000080;
font-family: 'Times New Roman', Garamond, Georgia, Serif;
text-align: center;
font-size: 24pt;
font-weight: bold;
text-decoration: none }
.housetitle {
color: #0000FF;
font-family: Georgia, Times New Roman, Courier New;
font-size: 16pt;
font-weight: bold;
text-decoration: none }
.names {
font-family: Verdana;
font-size: 10pt }
</style>
<title>Grier Summer Camp</title>
</head>
<body>
<p class='toptitle'>Grier Summer Camp</p>
<p class='housetitle'>Registration</p>
<p>Please use this form to register.</p>
<form action="index.aspx" method="get">
<table border="0" width="320">
<tr>
<td width="100" class="names">First Name:</td>
<td>
<input type="text" name="txtFirstName" size="10"
value="<%=HttpUtility.HtmlEncode(Request.QueryString["txtFirstName"])%>">
</td>
</tr>
<tr>
<td width="100" class="names">Last Name:</td>
<td>
<input type="text" name="txtLastName" size="10"
value="<%=HttpUtility.HtmlEncode(Request.QueryString["txtLastName"])%>">
</td>
</tr>
<tr>
<td width="100" valign="top" class="names">Full Name:</td>
<td>
<input type="text"
name="txtFullName"
size="21"
value="<%=HttpUtility.HtmlEncode(Request.QueryString["txtFirstName"]) +
" " +
HttpUtility.HtmlEncode(Request.QueryString["txtLastName"])%>">
<input type="submit" value="Submit it">
</td>
</tr>
</table>
</form>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<hr color="#FF0000">
</td>
</tr>
<tr>
<td width="100%"
align="center"
style="font-family: Verdana; font-size: 10pt">
Copyright © 2009 Grier Summer Camp
</td>
</tr>
</table>
</body>
</html>
|
|
|||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||