Page 216 - DCAP408_WEB_PROGRAMMING
P. 216
Web Programming
Notes
Did u know? What is the ACTION Property, Client-Side Form Validation
We have covered some of the basics of forms; it’s time to discuss some of the more
advanced form techniques. We’ve focused most of our attention so far on the various type
of form fields. Each form field is responsible for gathering a discrete chunk of information
from the user, while the form is responsible for gathering this information and sending it
to an ASP page for processing.
To accomplish this, the <FORM> tag has two properties: Method and Action. The METHOD
property determines how the information is passed to the form processing script. As we
know that Method property can be set to either GET or POST. The ACTION property
determines to what form processing script to send the users’ information.
Listing : EnglishToMetric.aspx: Converting Feet and Inches to Meters
1: <%@ Page Language=”C#” %>
2: <html>
3: <body>
4: <form runat=”server”>
5: <h2>English to Metric conversion</h2>
6: <h3>please enter your height, and then click the Convert button</h3>
7: <asp:Textbox id=”Feet” runat=”server”/>Feet
8: <br>
9: <asp:Textbox id=”Inches” runat=”server”/>Inches
10: <br>
11: <asp:Button OnClick=”OnConvert” Text=”Convert” runat=”server”/>
12: <br>
13: <br>
14: <asp:Label id=”lblMeters” runat=”server”/>
15: </form>
16: </body>
17: </html>
18:
19: <script runat=”server”>
20: void Page_Load(Object Sender, EventArgs e)
21: {
22: if(IsPostBack) {
23: if(Feet.Text == “”) {
24: Feet.Text = “0”;
25: }
26: if(Inches.Text == “”) {
27: Inches.Text = “0”;
210 LOVELY PROFESSIONAL UNIVERSITY