|
技术资料 > ASP技术 > 客户端相关 : ASP+ FORM handler例子 |
ASP+ FORM handler例子 March 25,2004 |
<%@ Page Language="VB" ClientTarget="downlevel" %>
<%@ Import Namespace="System.Text" %>
<script language="VB" runat="server">
Const strCheckMarkHtml As String = "<img src=""./images/check.gif"" border=""0"" width=""25""
height=""25"" />"
Sub Page_Load(Src as object, E as EventArgs)
lblStatus.Visible = False
validName.ErrorMessage = strCheckMarkHtml
validEmailRequired.ErrorMessage = strCheckMarkHtml
validEmailRegExp.ErrorMessage = strCheckMarkHtml
validAddress.ErrorMessage = strCheckMarkHtml
validCity.ErrorMessage = strCheckMarkHtml
validStateRequired.ErrorMessage = strCheckMarkHtml
validStateRegExp.ErrorMessage = strCheckMarkHtml
validZipRequired.ErrorMessage = strCheckMarkHtml
validZipRegExp.ErrorMessage = strCheckMarkHtml
End Sub
Sub btnReset_OnClick(Sender As Object, E As EventArgs)
lblStatus.Visible = False
txtName.Text = ""
txtEmail.Text = ""
txtAddress.Text = ""
txtCity.Text = ""
txtState.Text = ""
txtZip.Text = ""
End Sub
Sub btnSubmit_OnClick(Sender As Object, E As EventArgs)
Dim strLabelText As StringBuilder = new StringBuilder()
If Page.IsValid Then
divFormSection.Visible = False
strLabelText.Append("Your entry meets our validation criteria!")
strLabelText.Append("<br /><br />")
strLabelText.Append("This would naturally be the point where ")
strLabelText.Append("you just entered data would be getting ")
strLabelText.Append("logged to a file, inserted into a database, ")
strLabelText.Append("mailed off to someone, or whatever your ")
strLabelText.Append("plans for it might happen to be! Since ")
strLabelText.Append("we're just playing with the form here, I ")
strLabelText.Append("simply show it below.<br /><br />")
strLabelText.Append("<b>Here's what you entered:</b><br />")
strLabelText.Append("Name: " & txtName.Text & "<br />" & vbCrLf)
strLabelText.Append("Email: " & txtEmail.Text & "<br />" & vbCrLf)
strLabelText.Append("Address: " & txtAddress.Text & "<br />" & vbCrLf)
strLabelText.Append("City: " & txtCity.Text & "<br />" & vbCrLf)
strLabelText.Append("State: " & txtState.Text & "<br />" & vbCrLf)
strLabelText.Append("Zip: " & txtZip.Text & "<br />" & vbCrLf)
lblStatus.Text = strLabelText.ToString()
lblStatus.Visible = True
Else
strLabelText.Append("I'm sorry but your form wasn't filled ")
strLabelText.Append("out correctly. Please correct the ")
strLabelText.Append("fields indicated by the check marks.")
lblStatus.Text = strLabelText.ToString()
lblStatus.Visible = True
End If
strLabelText = Nothing
End Sub
</script>
<html>
<body>
<asp:label id="lblStatus" runat="server">
</asp:label>
<asp:Panel id="divFormSection" runat="server">
<form action="form_handler.aspx" method="post" runat="server">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right"><b>Name:</b></td>
<td rowspan="6"> </td>
<td>
<asp:TextBox id="txtName" runat="server" />
<asp:RequiredFieldValidator runat="server"
id="validName" ControlToValidate="txtName"
display="Dynamic" />
</td>
</tr>
<tr>
<td align="right"><b>Email:</b></td>
<td>
<asp:TextBox id="txtEmail" runat="server" />
<asp:RequiredFieldValidator runat="server"
id="validEmailRequired" ControlToValidate="txtEmail"
display="Dynamic" />
<asp:RegularExpressionValidator runat="server"
id="validEmailRegExp" ControlToValidate="txtEmail"
ValidationExpression="^[w-]+@[w-]+.
(com|net|org|edu|mil)$"
Display="Dynamic" />
</td>
</tr>
<tr>
<td align="right"><b>Address:</b></td>
<td>
<asp:TextBox id="txtAddress" runat="server" />
<asp:RequiredFieldValidator runat="server"
id="validAddress" ControlToValidate="txtAddress"
display="Dynamic" />
</td>
</tr>
<tr>
<td align="right"><b>City:</b></td>
<td>
<asp:TextBox id="txtCity" runat="server" />
<asp:RequiredFieldValidator runat="server"
id="validCity" ControlToValidate="txtCity"
display="Dynamic" />
</td>
</tr>
<tr>
<td align="right"><b>State:</b></td>
<td>
<asp:TextBox id="txtState" runat="server" />
<asp:RequiredFieldValidator runat="server"
id="validStateRequired" ControlToValidate="txtState"
display="Dynamic" />
<asp:RegularExpressionValidator runat="server"
id="validStateRegExp" ControlToValidate="txtState"
ValidationExpression="^w{2}$"
Display="Dynamic" />
</td>
</tr>
<tr>
<td align="right"><b>Zip:</b></td>
<td>
<asp:TextBox id="txtZip" runat="server" />
<asp:RequiredFieldValidator runat="server"
id="validZipRequired" ControlToValidate="txtZip"
display="Dynamic" />
<asp:RegularExpressionValidator runat="server"
id="validZipRegExp" ControlToValidate="txtZip"
ValidationExpression="^d{5}$"
Display="Dynamic" />
</td>
</tr>
</table>
<asp:Button type="reset" id="btnReset" text="Clear The Form" OnClick="btnReset_OnClick"
runat="server" />
<asp:Button type="submit" id="btnSubmit" text="Submit The Form" OnClick="btnSubmit_OnClick"
runat="server" />
</form>
</asp:Panel>
</body>
</html> |
|
Copyright © 2001-2008 Shenzhen Hiblue Software Team All rights reserved