惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
小众软件
小众软件
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
S
Secure Thoughts
O
OpenAI News
P
Proofpoint News Feed
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
Tenable Blog
A
Arctic Wolf
L
LINUX DO - 热门话题
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog

博客园 - henry

Smark.Net.Tcp.XmlService性能测试程序 基于Flex的http简易文件管理工具 性能的瓶颈到底在那呢? 运用Smark.SocketAsyncs扩展基于XML的TCP服务 运用Smark.SocketAsyncs方便实现数据交互服务 实现分布式对象锁 发布一个C#实现的Asterisk的管理系统 asterisk使用SIP相互对接 开源一个基于Flex4+C#的个人信息管理程序 FlashBuilder4试用 这样的重构是否有必要呢? Asterisk2B用户管理逻辑设计 用JQuery UI dialog实现Alert和Confirm功能 - henry Asterisk发起电话预约回拔 WOW工会DKP管理系统 我的分页控件设计 Smark.Data 实体属性值描述 Smark.Data实体成员数据验证 Smark.Data Part1
实现一个JavaScript验证的Asp.net Helper - henry - 博客园
henry · 2009-09-25 · via 博客园 - henry
 

       WEB应用在HTML里写JavaScript(JS)验证数据是正常的事情,但VS.NETJS的智能感知支持远没有C#这么强大,因此在写JS写多了也是麻烦的事情。为了方便所以写了一个Helper方便生成js验证代码。

先看下在应用中的代码:

    <form action="Register.aspx" method="post" onsubmit="return VRegister()">

    <p>用户名:<%=HtmlHelper.Input(InputType.text, "UserName").Value(view.User.UserName).Id("user")%><label id="usertip" /></p>

    <p>密码:<%=HtmlHelper.Input(InputType.password,"UserPWD").Id("pwd") %><label id="pwdtip" /></p>

    <p>确认密码:<%=HtmlHelper.Input(InputType.password,"RPWD").Id("rpwd") %><label id="rpwdtip" /></p>

    <p>邮件地址:<%=HtmlHelper.Input(InputType.text, "EMail").Value(view.User.EMail).Id("email")%><label id="emailtip" /></p>

    <p><input type="submit" value="注册" /></p>

    <p></p>

    </form>

        <%JSValidator jsv = new JSValidator("VRegister");

          jsv.Add(jsv.Create("user", "usertip").NotNull("请输入用户名!", null),

              jsv.Create("pwd","pwdtip").NotNull("请输入密码!",null),

              jsv.Create("rpwd","rpwdtip").NotNull("请输入确认密码!",null).StringCompare("pwd", CompareType.eq,"密码不一致!",null),

              jsv.Create("email","emailtip").NotNull("请输入邮件地址!",null).EMail("非法邮件地址!",null));

        %>

        <%=jsv %>

灰色部分代码就是验证Helper的代码,通过C#代码能够很快的完成输写。

实际的应用效果:

 

JS功能代码

Code


c# helper代码

Code

Code

扩展Ajax功能

Code

Code