帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
ASP+ FORM handler例子
作者: 发布时间:2005-03-12 来源:
<%@ 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>
  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·如何在ASP+中发送邮件  (2005-03-12)
 ·asp+初体验---用c#写的asp+域名查  (2005-03-12)
 ·ASP+中执行简单的Select查询,并  (2005-03-12)
 ·ASP+页缓存OutputCache Duration  (2005-03-12)
 ·ASP+培训教材(1)  (2005-03-12)
 ·让您的主页支持各种浏览设备(AS  (2005-03-12)
 ·asp+ VB上传文件代码  (2005-03-12)
 ·让您的主页支持各种浏览设备(AS  (2005-03-12)
 ·让您的主页支持各种浏览设备(AS  (2005-03-12)
 ·ASP爱好者网站首页(ASP+版本)代码  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统