当设置InitialValue时,RequiredFieldValidator允许空值! [英] RequiredFieldValidator allows blank values when InitialValue is set!!

查看:271
本文介绍了当设置InitialValue时,RequiredFieldValidator允许空值!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我在文本框上使用此验证器,并且发现如果我设置了InitialValue属性,那么验证器会正确触发如果

用户没有更改文本框的初始值,但如果文本框为空则不会触发
!!


我认为这个验证器的重点是确保控制

被验证有一些文本。我做了些蠢事吗?它看起来好像我需要*两个*验证器,一个用于检查

初始值,另一个用于检查那里有什么东西。这是愚蠢的,

没有?


这是一些代码...


< asp :TextBox ID =" txtAddr1"文本= QUOT;地址]按钮RUNAT = QUOT;服务器" />


< br>< asp:RequiredFieldValidator ID =" reqTxtAddr1"

ControlToValidate =" txtAddr1"与InitialValue = QUOT;地址]按钮ErrorMessage =""

Text =" Required"显示= QUOT;动态" RunAt =" server" />


TIA,你可以获得任何光线。


-

Alan Silver

(此行下面添加的任何内容都与我无关)

Hello,

I am using this validator on a textbox, and have discovered that if I
set the InitialValue property, then the validator correctly fires if the
user does not change the initial value of the textbox, but does NOT fire
if the textbox is empty!!

I thought the whole point of this validator was to ensure the control
being validated had some text. Am I doing something stupid? It looks
like I am going to need *two* validators for this, one to check for the
initial value and one to check there''s something there. That''s stupid,
no?

Here is some code...

<asp:TextBox ID="txtAddr1" Text="address" RunAt="server" />

<br><asp:RequiredFieldValidator ID="reqTxtAddr1"
ControlToValidate="txtAddr1" InitialValue="address" ErrorMessage=""
Text="Required" Display="Dynamic" RunAt="server"/>

TIA for any light you can shed on this.

--
Alan Silver
(anything added below this line is nothing to do with me)

推荐答案




InitialValue指定RequiredFieldValidator应该为相关控件认为无效的文本
并显示错误消息。它b / b
不代表文本框中显示的初始值。


在您的情况下,除地址以外的任何文本都被认为是有效期为

文本框因此RFV无法触发。


Alan Silver <人********* @ nospam.thanx>在消息中写道

news:87 ************** @ nospamthankyou.spam ...

您好,


我在文本框上使用这个验证器,并且发现如果我设置了InitialValue属性,那么验证器会正确触发,如果

用户不会更改文本框的初始值,但如果文本框为空则不会触发
!!


我认为这个验证器的重点是为了确保控制

被验证有一些文字。我做了些蠢事吗?它看起来好像我需要*两个*验证器,一个用于检查

初始值,另一个用于检查那里有什么东西。这是愚蠢的,

没有?


这是一些代码...


< asp :TextBox ID =" txtAddr1"文本= QUOT;地址]按钮RUNAT = QUOT;服务器" />


< br>< asp:RequiredFieldValidator ID =" reqTxtAddr1"

ControlToValidate =" txtAddr1"与InitialValue = QUOT;地址]按钮ErrorMessage =""

Text =" Required"显示= QUOT;动态" RunAt =" server" />


TIA,你可以获得任何光线。


-

Alan Silver

(此行下面添加的任何内容都与我无关)
Hi,

InitialValue specifies the text that the RequiredFieldValidator should
consider invalid for the associated control and show the error message. It
does not represent the intial value to show in the textbox.

In your case, any text other than ''address'' is considered to be valid for
the textbox and hence RFV doesn''t fire.

"Alan Silver" <al*********@nospam.thanx> wrote in message
news:87**************@nospamthankyou.spam...
Hello,

I am using this validator on a textbox, and have discovered that if I
set the InitialValue property, then the validator correctly fires if the
user does not change the initial value of the textbox, but does NOT fire
if the textbox is empty!!

I thought the whole point of this validator was to ensure the control
being validated had some text. Am I doing something stupid? It looks
like I am going to need *two* validators for this, one to check for the
initial value and one to check there''s something there. That''s stupid,
no?

Here is some code...

<asp:TextBox ID="txtAddr1" Text="address" RunAt="server" />

<br><asp:RequiredFieldValidator ID="reqTxtAddr1"
ControlToValidate="txtAddr1" InitialValue="address" ErrorMessage=""
Text="Required" Display="Dynamic" RunAt="server"/>

TIA for any light you can shed on this.

--
Alan Silver
(anything added below this line is nothing to do with me)


>
InitialValue指定RequiredFieldValidator应该认为对关联控件无效的文本并显示错误消息。它不代表文本框中显示的初始值。


我知道,如果你看看我的例子,我会把地址放在作为文本框中的初始值



在您的情况下,地址以外的任何文本都被视为对文本框有效因此RFV不会发射。


肯定是必填字段字样在控件名称中暗示

验证器应确保该字段具有非空值。最初的

值只是一个额外的约束条件,表示非空的
值不能等于初始值。


如果我只想要控件不应该有地址在它,然后一个

CompareValidator将是一个更合理的选择。


我对这些验证器印象不深。它们比

更好,但它们似乎距离标记很远。


我发现如果你使用RegularExpressionValidator <使用ValidationExpression为\w {6,15}的
,然后它还允许空白

值。当然,我指定一个最小长度的事实应该

排除空白值?


欢迎任何进一步的评论。

" ; Alan Silver <人********* @ nospam.thanx>在消息中写道
新闻:87 ************** @ nospamthankyou.spam ...
你好,

我正在使用这个验证器在文本框上,并且发现如果我设置了InitialValue属性,那么如果
用户没有更改文本框的初始值,则验证器会正确触发,但是如果没有,则不会触发
如果文本框是空的!!

我认为这个验证器的重点是确保控件验证有一些文本。我做了些蠢事吗?它看起来好像我需要*两个*验证器,一个用于检查
初始值,一个用于检查那里有什么东西。那是愚蠢的,
没有?

这里有一些代码...

< asp:TextBox ID =" txtAddr1"文本= QUOT;地址]按钮RUNAT = QUOT;服务器" />

< br>< asp:RequiredFieldValidator ID =" reqTxtAddr1"
ControlToValidate =" txtAddr1"与InitialValue = QUOT;地址]按钮ErrorMessage =""
Text =" Required"显示= QUOT;动态" RunAt =" server" />

TIA可以解决任何问题。

InitialValue specifies the text that the RequiredFieldValidator should
consider invalid for the associated control and show the error message. It
does not represent the intial value to show in the textbox.
I know, if you look at my example, I put "address" as the initial value
in the textbox myself.
In your case, any text other than ''address'' is considered to be valid for
the textbox and hence RFV doesn''t fire.
Surely the words "required field" in the control name imply that the
validator should ensure the field has a non-empty value. The initial
value would simply be an extra constraint to say that the non-empty
value can''t be equal to the initial value.

If I only wanted that the control shouldn''t have "address" in it, then a
CompareValidator would be a more logical choice.

I''m not too impressed with these validators. They are better than
nothing, but they seem to be a long way short of the mark.

I have since discovered that if you use a RegularExpressionValidator
with a ValidationExpression of "\w{6,15}", then it also allows blank
values. Surely the very fact that I specified a minimum length should
preclude a blank value?

Any further comments welcome.
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:87**************@nospamthankyou.spam...
Hello,

I am using this validator on a textbox, and have discovered that if I
set the InitialValue property, then the validator correctly fires if the
user does not change the initial value of the textbox, but does NOT fire
if the textbox is empty!!

I thought the whole point of this validator was to ensure the control
being validated had some text. Am I doing something stupid? It looks
like I am going to need *two* validators for this, one to check for the
initial value and one to check there''s something there. That''s stupid,
no?

Here is some code...

<asp:TextBox ID="txtAddr1" Text="address" RunAt="server" />

<br><asp:RequiredFieldValidator ID="reqTxtAddr1"
ControlToValidate="txtAddr1" InitialValue="address" ErrorMessage=""
Text="Required" Display="Dynamic" RunAt="server"/>

TIA for any light you can shed on this.




-

Alan Silver

(此行下面添加的任何东西都与我无关)



--
Alan Silver
(anything added below this line is nothing to do with me)


这个类的文档实际上确实调用了您所看到的

行为。

http://msdn.microsoft.com/library/de...valuetopic.asp


这显然是设计的。这是一个很好的设计吗?这是讨论

的讨论,但这确实是文件说它应该做的b $ b。

The documentation for this class actually calls out exactly the
behavior that you are seeing.

http://msdn.microsoft.com/library/de...valuetopic.asp

This is apparently by design. Is this a good design? That is up for
discussion, but that is indeed what the documentation says that it
should do.

这篇关于当设置InitialValue时,RequiredFieldValidator允许空值!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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