关于验证的问题 [英] A question about validate

查看:70
本文介绍了关于验证的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的asp.net表单上有三个webcontrol:一个TextBox,一个提交按钮

和一个RegularExpressionValidator。我已经将RegularExpressionValidator的ControlToValidate属性

设置为TextBox。但现在,当我在文本框中输入

字符串并按Enter键时,表单提交时没有

客户端javascript验证。


为什么?在提交表单之前我应该​​怎么做才能启用客户端验证

按Enter键或点击提交按钮?


谢谢!

There are three webcontrol on my asp.net form: a TextBox, a submit button
and a RegularExpressionValidator. And I had set ControlToValidate property
of the RegularExpressionValidator to the TextBox. But now, when I input a
string in the textbox and press Enter key, the form was submit without
client javascript validate.

Why? And what should I do to enable client validate before submit the form
whethe press Enter key or click Submit button?

Thanks!

推荐答案

" wolf" < a@b.c>在留言中写道

新闻:O0 ************** @ TK2MSFTNGP11.phx.gbl ...
"wolf" <a@b.c> wrote in message
news:O0**************@TK2MSFTNGP11.phx.gbl...
有三个webcontrol on我的asp.net表单:TextBox,提交按钮
和RegularExpressionValidator。我已经将RegularExpressionValidator的ControlToValidate属性设置为TextBox。但现在,当我在文本框中输入一个
字符串并按Enter键时,表单提交时没有客户端javascript验证。

为什么?如何在提交表单之前启用客户端验证
按Enter键或单击提交按钮?
There are three webcontrol on my asp.net form: a TextBox, a submit button
and a RegularExpressionValidator. And I had set ControlToValidate property
of the RegularExpressionValidator to the TextBox. But now, when I input a
string in the textbox and press Enter key, the form was submit without
client javascript validate.

Why? And what should I do to enable client validate before submit the form
whethe press Enter key or click Submit button?




当您说提交按钮时,请执行此操作你的意思是< input type =" submit"> ?如果是这样,那么ASP.NET如何知道单击该按钮以便它可以进行

客户端验证的时候怎么样?


尝试使用< asp:Button>并查看是否能解决问题。


John Saunders



When you say a Submit button, do you mean <input type="submit"> ? If so, how
would ASP.NET know when that button is clicked so that it can do the
client-side validation?

Try using an <asp:Button> and see if that fixes the problem.

John Saunders


>当您说提交按钮时,您的意思是< input type =" submit"> ?如果是这样,

如何
> When you say a Submit button, do you mean <input type="submit"> ? If so,
how
ASP.NET知道何时单击该按钮以便它可以进行客户端验证?

尝试使用< asp:Button>并查看是否能解决问题。

John Saunders
would ASP.NET know when that button is clicked so that it can do the
client-side validation?

Try using an <asp:Button> and see if that fixes the problem.

John Saunders




否,所有控件都是服务器端Web控件,以下是我的

代码在WebPage1.aspx中:

<%@ Page language =" c#" Codebehind =" WebForm1.aspx.cs"

AutoEventWireup =" false"继承= QUOT; web1.WebForm1" %>

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.0 Transitional // EN" >

< HTML>

< HEAD>

< title> WebForm1< / title>

< meta name =" GENERATOR" Content =" Microsoft Visual Studio .NET 7.1"

< meta name =" CODE_LANGUAGE" Content =" C#">

< meta name =" vs_defaultClientScript" content =" JavaScript">

< meta name =" vs_targetSchema"

content =" http://schemas.microsoft.com/intellisense/ie5" ;>

< / HEAD>

< body MS_POSITIONING =" GridLayout">

< form id =" Form1中"方法= QUOT;交" runat =" server">

< FONT face =" ??ì?">

< asp:TextBox id =" TextBox1" style =" Z-INDEX:101;左:48px;位置:

绝对值; TOP:56px runat =" server">< / asp:TextBox>

< asp:RegularExpressionValidator id =" RegularExpressionValidator1"

style =" Z-INDEX: 103;左:216px;位置:绝对; TOP:56px"

runat =" server" ErrorMessage =" RegularExpressionValidator"

ControlToValidate =" TextBox1"

ValidationExpression =" \w +([ - +。] \ w +)* @ \ w + ([ - 。] \ w +)* \.\\\ +([ - 。] \ w +)*">< / asp:Reg

ularExpressionValidator>

< asp:Button id =" Button1" style =" Z-INDEX:102;左:144px;位置:

绝对值; TOP:96px runat =" server"

Text =" Button">< / asp:Button>< / FONT>

< / form>

< / body>

< / HTML>



No, all of the control are server side web control, and the following is my
code in WebPage1.aspx:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="web1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="??ì?">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 48px; POSITION:
absolute; TOP: 56px" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator id="RegularExpressionValidator1"
style="Z-INDEX: 103; LEFT: 216px; POSITION: absolute; TOP: 56px"
runat="server" ErrorMessage="RegularExpressionValidator"
ControlToValidate="TextBox1"
ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:Reg
ularExpressionValidator>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 144px; POSITION:
absolute; TOP: 96px" runat="server"
Text="Button"></asp:Button></FONT>
</form>
</body>
</HTML>


我的目标是数据应该是如果他们被提交到服务器

那边有效。但如果我按Enter键

而不是提交按钮,数据将在验证前提交。
My goal is that the data should be valid if they are submitted to the server
side. But the data will be submitted before validate if I press Enter key
instead of submit button.


这篇关于关于验证的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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