RE: RequiredFieldValidator question

S

Steven Cheng[MSFT]

Hi,

From your description, you used a RequiredFieldVadliator on a textbox and
found that when the textbox is set visible = false on serverside. When the
page is submit, the clientside validation not fire ,but the serverside
validation still fire, yes?

I think this behavior is reasonable as Curt has metioned that when the
ASP.NET TextBox's visible is set to false, it won't be renedered out
(<input type="text" ..>) as the html element on the page( you can view the
page source in browser to confirm this). However, the validation control is
not disabled , so it'll still validate both on client and serverside. The
reason why the clientside validation not fire is because the clientside
validtion is using javascript to find the certain htmlelement and validate
the element's value. when textbox visible=false, we can find the html
element in the page's dom collectoin so the validtion not work(but no means
haven't been executed). And at serverside, since the textbox still existing
, so the validation will work as normal. Do you think so?

So if you want to make the validation not be fired (no matter at client or
at server), the correct way is to explicitly set the
RequiredFieldValidator's Enabled property to false when the TextBox(it will
validate) is set to invisible.

IN addition, here is a tech article which has provide detailed description
on the ASP.NET validation controls' infrastructure:
#ASP.NET Validation in Depth
http://msdn.microsoft.com/library/en-us/dnaspp/html/aspplusvalid.asp?frame=t
rue

Hope also helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
P

Peter Blum

While I agree with Steven's solution, the reasoning isn't so hot. (Sorry,
Steven.)

Validation is about communicating with the user and giving them a chance to
deal with the problem. In this situation, the default validator will show an
error message and set Page.IsValid=false while the user cannot fix the
problem (because the field is invisible).

FYI: In my replacement to Microsoft's validators, "Professional Validation
And More" (http://www.peterblum.com/vam/home.aspx), my validators
automatically go silent when the Control To Validate is invisible. In
addition, my 22 validators have a smart enabling property to detect other
conditions that should silence them, such as if a checkbox on the page is
not checked, we don't care about the TextBox so the validators should
disable themselves.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top