如何验证code为ASP.NET窗体与VB编码 [英] how to make a validation code for ASP.NET form with VB coding

查看:130
本文介绍了如何验证code为ASP.NET窗体与VB编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试建立一个表单+附件需要被发送到电子邮件。
即时通讯使用的是VB背景code(attachementemail.aspx.vb)
和我的前(B-16.aspx)

im trying to build a form+attachment that needs to be send to email. Im using a VB background code (attachementemail.aspx.vb) and my front (b-16.aspx)

我要的页面来检查用户输入一个电子邮件,姓名,PHONENUMBER和附件。

I want the page to check that the user entered a email, name, phonenumber and attachment.

我把在axp.vb什么命令
并在.aspx什么

what command do I put in the axp.vb and what on the .aspx

尝试任何事情。

推荐答案

在它的基础层面,你可以在你的表单中使用的RequiredFieldValidator和CustomValidation。你可以使用一些正则表达式的逻辑电子邮件,我用这个,但也有很多了:

At it's basic level you could use RequiredFieldValidator and CustomValidation in your form. You can use some regex logic for email, I use this but there are many out there:

正则表达式(@\\ w +([ - +] \\ w +)的 @ \\ w +([ - ] \\ w +)的\\ w +([ - ] \\ w +)*)

Regex(@"\w+([-+.]\w+)@\w+([-.]\w+).\w+([-.]\w+)*")

我个人使用客户端的JavaScript它击中服务器之前,一旦它击中服务器,然后我重新验证的条目。如果你使用回发事件,那么你就需要更新面板和一个ScriptManager(不知道你是否意识到这一点了,所以道歉,如果教你班门弄斧!)。

Personally I use client side javascript before it hits the server and then I re-validate the entries once it hits the server. If your using the postback events then you'll need update panels and a scriptmanager (not sure if you are aware of this already, so apologies if teaching you to suck eggs!).

下面是一个例子:

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
    ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>

背后code(抱歉,这是C#)

Code behind (sorry this is in c#)

protected void Button1_Click(object sender, EventArgs e)
{
    if (RequiredFieldValidator1.IsValid)
    {
        Label1.Text = "Has content";
    }
    else
    {
        Label1.Text = "Not valid";
    }
}

请注意,所需的字段校验器都有它自己的方法,在这里嘿,你还没有进入内容我的朋友显示消息,但我必须补充说,该标签来代替。

Note that the required field validator has it's own methods to display a "hey you haven't entered content here my friend" message, but i have added that to the label instead.

这篇关于如何验证code为ASP.NET窗体与VB编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆