1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
<%@ Page AutoEventWireup="True" %>
<html>
<head>
<script language="C#" runat="server">
public void Button_Click (object sender, EventArgs e)
{
Random rand_number = new Random();
Compare1.ValueToCompare = rand_number.Next(1,10).ToString();
Compare1.Validate();
if (Page.IsValid)
lblOutput.Text = "You guessed correctly!!";
else
lblOutput.Text = "You guessed poorly";
lblOutput.Text += "<br><br>" + "The number is: " + Compare1.ValueToCompare;
}
</script>
</head>
<body>
<form runat=server>
<h3>Validator Example</h3>
<h5>Pick a number between 1 and 10:</h5>
<asp:TextBox id="TextBox1"
runat="server"/>
<asp:CompareValidator id="Compare1"
ControlToValidate="TextBox1"
ValueToCompare="0"
EnableClientScript="False"
Type="Integer"
Display="Dynamic"
ErrorMessage="Incorrect guess!!"
Text="*"
runat="server"/>
<asp:RequiredFieldValidator id="Require1"
ControlToValidate="TextBox1"
EnableClientScript="False"
Display="Dynamic"
ErrorMessage="No number entered!!"
Text="*"
runat="server"/>
<br><br>
<asp:Button id="Button1"
Text="Submit"
OnClick="Button_Click"
runat="server"/>
<br><br>
<asp:Label id="lblOutput"
Font-Name="verdana"
Font-Size="10pt"
runat="server"/>
<br><br>
<asp:ValidationSummary
id="Summary1"
runat="server"/>
</form>
</body>
</html>
|