473,378 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

RequiredFieldValidator allows blank values when InitialValue is set!!

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)
Nov 19 '05 #1
11 8592
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)
Nov 19 '05 #2
>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.
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
(anything added below this line is nothing to do with me)
Nov 19 '05 #3
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.

Nov 19 '05 #4
Also, in response to your comment about the RegularExpressionValidator
not failing on empty text, see the documentation:

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

It says this:

Note Validation succeeds if the input control is empty. If a value is
required for the associated input control, use a RequiredFieldValidator
control in addition to the RegularExpressionValidator control.

Nov 19 '05 #5
Perhaps, you can consider having two validator controls for your textbox:
one RFV with default InitialValue (empty string) to prevent empty value and
one CompareValidator to check the value is not 'address'. Will that be ok?

"Alan Silver" <al*********@nospam.thanx> wrote in message
news:er**************@nospamthankyou.spam...
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.
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
(anything added below this line is nothing to do with me)
Nov 19 '05 #6
>Also, in response to your comment about the RegularExpressionValidator
not failing on empty text, see the documentation:

http://msdn.microsoft.com/library/de.../en-us/cpref/h
tml/frlrfsystemwebuiwebcontrolsrequiredfieldvalidatorc lassinitialvalueto
pic.asp

It says this:

Note Validation succeeds if the input control is empty. If a value is
required for the associated input control, use a RequiredFieldValidator
control in addition to the RegularExpressionValidator control.


OK, another case of (IMO) very poor design.

If a regex has a {4,10} at the end, it surely says that the value to be
evaluated MUST be between 4 and 10 characters. To allow such a validator
to pass an empty value seems like poor design to me.

Still, I'm not in control of the design, I'm just trying to find out
what it does and how. At least I'm informed now!!

Thanks again

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #7
>Perhaps, you can consider having two validator controls for your
textbox: one RFV with default InitialValue (empty string) to prevent
empty value and one CompareValidator to check the value is not
'address'. Will that be ok?


I don't really have much choice do I? I am seriously considering writing
my own validators as the MS ones seem very badly designed. Most of what
they do is pretty simple anyway, it's just a shame that MS didn't do it
right.

Ta ra

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #8
>The documentation for this class actually calls out exactly the
behavior that you are seeing.
Oh, I must have missed that. Mind you, I was using a book as a basis for
info, not the MS docs.
http://msdn.microsoft.com/library/de.../en-us/cpref/h
tml/frlrfsystemwebuiwebcontrolsrequiredfieldvalidatorc lassinitialvalueto
pic.asp
I must say that, even after reading that, it's not very clear that this
behaviour is intended. Yes, when you read it carefully, and with the
hindsight of knowing it does this, it does say this, but on first
reading I don't think it is easily noticeable.
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.


Oh well, I can't say I am impressed with the design choice here, but at
least it's not a bug.

Thanks for the info. Looks like I need two validators to perform this
amazingly simple task.

I think I'll write my own. I've found so many issues with the MS
validators.

Ta ra

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #9
So use two RequiredFieldValidators.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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.

Nov 19 '05 #10
>So use two RequiredFieldValidators.

I'm going to have to. I just seems poor design to need two validators
when the one should do the job.

I know, when I design ASP.NET 3.0, I'll do it differently ;-)
-Brock
DevelopMentor
http://staff.develop.com/ballen
Hello,
I am using this validator on a textbox, and have discovered that if

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)
Nov 19 '05 #11
The validators supplied with ASP.NET are not very feature rich. That's why
several third parties have created replacements to the Microsoft validators.
Mine is "Professional Validation And More"
(http://www.peterblum.com/vam/home.aspx). Its replacement for
RequiredFieldValidator allows a list of items for the InitialValue property
(actually I call it the UnassignedValues property). You can define that both
blank text and a specific text item indicates the textbox is unassigned.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"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)

Nov 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: awightma | last post by:
Hi, I have a datagrid with a number of textboxes on it. I want one column of my table to be visible=false because it contains the id of the record from the table. For some reason when I set...
0
by: Daniel | last post by:
when i set the BackgroundImage property in the designer the image still doesnt show in the background of the textbox any other property must be set?
2
by: Anand | last post by:
Hi All, I have a combobox with style as DropDown List. When I set the combobox.selectedIndex = 0, the first value is not showing up in the combobox and it is simply blank. Only if I...
2
by: Ken Loomis | last post by:
Hello: I'm using the validating event on a text boxes to test for valid dates, doubles, etc. The problem is that if the field is not required and a blank value is OK and the user deletes a...
6
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
3
by: S_K | last post by:
Hi, I have a list of 6 DropDownList boxes, from DropDownList1 to DropDownList6, and I'm changing the SelectedIndex of each using a foreach loop as follows: foreach(PaymentReqDisplay...
2
by: MicaK | last post by:
Good Morning, I am new to this forum, and extremely new to VBA, so there may be a very simple explanation to this. I also apologize if I am giving you and excessive amount of detail. I have a...
11
by: hannoudw | last post by:
Hi I have a form that contains 2 text boxes and a subform contain the Invoice details. the 1st text box is txtInvoice and its bound to Invoice_number in the invoice table , it's an auto-number. and...
1
by: Jaap van der Heijden | last post by:
Hi all, I've made the script below to calculate the coverage per position of small pieces of strings. It works fine but when I tried to speed thing up for large files using forkmanager the script...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.