.net 流氓
天下无难事,有志者成之;天下无易事,有恒者得之。
<script runat="server">
protected void Button1_Click(Object sender, EventArgs e) {
if (Page.IsValid) {
Label1.Text
= "Page is valid!";
}
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server" id="Head1">
<title>RequiredFieldValidator</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" Runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" Runat="server" Text="Required!" ControlToValidate="TextBox1">
</asp:RequiredFieldValidator>
<br />
<asp:Button ID="Button1" Runat="server" Text="Submit" OnClick="Button1_Click" />
<br />
<br />
<asp:Label ID="Label1" Runat="server"></asp:Label>
</div>
</form>
</body>
</html>

InitialValue 表示默认值 文本框

 

1 <script runat="server">
2 protected void Button1_Click(Object sender, EventArgs e) {
3 if (Page.IsValid) {
4 Label1.Text = "Page is valid!";
5 }
6 }
7  </script>
8
9 <html xmlns="http://www.w3.org/1999/xhtml" >
10 <head runat="server" id="Head1">
11 <title>RequiredFieldValidator</title>
12 </head>
13 <body>
14 <form id="form1" runat="server">
15 <div>
16 <asp:TextBox ID="TextBox1" Runat="server">My Initial Value</asp:TextBox>&nbsp;
17
18 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Runat="server"
19 Text="Please change value" ControlToValidate="TextBox1"
20 InitialValue="My Initial Value"></asp:RequiredFieldValidator>
21
22 <asp:RequiredFieldValidator ID="RequiredFieldValidator2" Runat="server"
23 Text="Do not leave empty" ControlToValidate="TextBox1">
24 </asp:RequiredFieldValidator>
25
26 <br />
27 <asp:Button ID="Button1" Runat="server" Text="Submit" OnClick="Button1_Click" />
28 <br />
29 <br />
30 <asp:Label ID="Label1" Runat="server"></asp:Label>
31 </div>
32 </form>
33 </body>
posted on 2011-06-14 06:44  .net 流氓  阅读(2097)  评论(0编辑  收藏  举报