Sorgenti: RequiredFieldValidator.aspx
Scarica i sorgenti: aspnet06.zip
Articolo a cui si riferisce il codice: ASP.NET: Validation Controls
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
4 <%@Page Language="VB"%>
5 <%@Register TagPrefix="ANet" TagName="Footer" Src="includes/footer.ascx"%>
6
7
8 <!—
9 # nome: RequiredFieldValidator.aspx
10 # scritto da: Antonio Volpon
11 # data creazione: 25 Ottobre 2001
12 # ultima modifica: 25 Ottobre 2001
13 # copyright: Antonio Volpon
14 —>
15
16 <script language="vb" runat="server">
17
18 Sub Button_Click(objSender as object, objArgs as EventArgs)
19
20 If Page.IsValid Then
21 risposta.InnerText = "Grazie per i tuoi dati."
22 Else
23 risposta.InnerText = "Devi compilare correttamente i campi."
24 End If
25
26 End Sub
27
28 </script>
29
30
31 <html>
32 <head>
33
34 <link rel="stylesheet" href="css/aspnet.css" type="text/css">
35 </link>
36 <title>Input Validation Controls: RequiredFieldValidator</title>
37
38 </head>
39
40 <body>
41 <div class="titolo">
42 Input Validation Controls: RequiredFieldValidator
43 </div>
44
45 <hr noshade="noshade" size="1" width="100%" />
46
47 <form runat="server">
48 <table border="0" align="center">
49 <tr>
50 <td align="right">Nome:</td>
51 <td><input type="text" id="txtNome" size="20" runat="server" /></td>
52 <td>
53 <asp:RequiredFieldValidator id="reqNome"
54 ControlToValidate="txtNome"
55 Display="Static"
56 runat="server">
57 * Campo obbligatorio
58 </asp:RequiredFieldValidator>
59 </td>
60 </tr>
61 <tr>
62 <td align="right">Cognome:</td>
63 <td><input type="text" id="txtCognome" size="20" runat="server" /></td>
64 <td>
65 <asp:RequiredFieldValidator id="reqCognome"
66 ControlToValidate="txtCognome"
67 Display="Static"
68 runat="server">
69 * Campo obbligatorio
70 </asp:RequiredFieldValidator>
71 </td>
72 </tr>
73 <tr>
74 <td align="right" colspan="2" align="right">
75
76 <input type="submit"
77 runat="server"
78 value="Invia"
79 onServerClick="Button_Click" />
80
81 </td>
82 <td> </td>
83 </tr>
84 </table>
85
86 </form>
87
88 <div class="risposta" runat="server" id="risposta" EnableViewState="false" />
89 <ANet:Footer id="Menu" runat="server" />
90
91 </body>
92 </html>