| |
8. 2. 12. Disable Client Validation |
|
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="DisableClientValidation" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
Quantity:<br />
<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox>
<asp:CompareValidator ID="compQuantity"
runat="server"
ControlToValidate="txtQuantity"
Operator="DataTypeCheck"
Type="Integer"
EnableClientScript="false"
Text="Enter a valid whole number" />
<asp:Button ID="btnSubmit" Text="Click this to test validation" runat="server" OnClick="btnSubmit_Click" />
<asp:Label ID="labContent" runat="server" />
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class DisableClientValidation : System.Web.UI.Page
{
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (IsValid)
{
int quantity = Convert.ToInt32(txtQuantity.Text);
int unitCost = 5;
int price = quantity * unitCost;
labContent.Text = "Price for order is $" + price;
}
}
}
|
|
|