Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net requiredfieldvalidator dont work when visible=false

I have some requiredFileldvalidators in my asp.net site that i want to set invisible until needed. But when i set them to visible=false they do not fire. They do work if they are set visible=true.

Is this the correct behavior of this control or is this wrong. I want them invisible due to styling issues when visible.

like image 351
espvar Avatar asked May 14 '26 19:05

espvar


2 Answers

Setting Visible="false" in ASP.NET will cause an element to not be rendered out to the page. So, it essentially doesn't exist on the client side. They should be invisible by default, and will only be shown if the criteria of requirements is not met (or they are otherwise forced by use of IsValid="false").

You can play with the Display property to help facilitate layout modes - but I have a feeling this is not entirely related to what you desire to do.

like image 150
Grant Thomas Avatar answered May 16 '26 07:05

Grant Thomas


I'm guessing it's because by default the RequiredFieldValidator hides itself by setting the visibility to hidden.

To get it to change display to none instead (which won't leave an empty gap on the page) remove your Visible="False" attribute and add this attribute to the control:

Display="Dynamic"
like image 24
greg84 Avatar answered May 16 '26 09:05

greg84