动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   Asp → 阅读文章

 ASP+ FORM handler例子

作者来源: 
阅读 2826 人次 , 2000-9-3 

<%@ 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">&nbsp;</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>  
 本文Tagsrealplayer  C#  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:ASP+数据库操作例子
· 下一篇:购物车的前台管理程序-只与服务器交互一次(二)
· Counters 组件参考(一) - 概述
· 在webclass中使用文件上传功能
· 不用图像组件的ASP图像计数器
· Ad Rotator 组件参考(四) - Ad Rotator 的属性
· ASP 3.0高级编程(二十七)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077