asp.net requiredfieldvalidator dont work when visi

2019-07-07 02:10发布

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.

5条回答
戒情不戒烟
2楼-- · 2019-07-07 02:28

The Visible property of a asp.net control has nothing to do with styling. Use css for that. Visible controls whether the control is displayed/rendered or not. Maybe your looking for Display="Dynamic"?

查看更多
Anthone
3楼-- · 2019-07-07 02:30

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.

查看更多
时光不老,我们不散
4楼-- · 2019-07-07 02:34

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"
查看更多
欢心
5楼-- · 2019-07-07 02:46

use validator's "Enabled" property instead, and also set Display property to Dynamic, so it does not take up space while rendering.

That should pretty much do what you need to do.

查看更多
Bombasti
6楼-- · 2019-07-07 02:53

Try to do this:

$("#myField").hide();

in jQuery, or:

style="display:none"

within the input tag.

Then in will be rendered but just not visible.

查看更多
登录 后发表回答