请验证还是在火灾ASP.NET即使控件被隐藏? [英] Do validations still fire in ASP.NET even if the controls are hidden?

查看:117
本文介绍了请验证还是在火灾ASP.NET即使控件被隐藏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ASP.NET验证的一种形式。我使用了一些内嵌C#中的ASPX显示/隐藏根据用户的角色一定的控制。我会使用Visible属性,但有这么多的人,我就决定做内联C#来显示和隐藏(我知道,不是最好的做法,但我承担第二次)。我有哪里Page.IsValid总是被设置为False一个问题,当我提出我的表格(在某些字段被隐藏)。将验证仍然脱火,即使控件没有连上呈现PAG?另外,如果不是这种情况,有没有打破Page.IsValid找出什么是它设置为False的有效途径?谢谢你。

I have a form that uses ASP.NET validations. I am using some inline C# in the aspx to show/hide certain controls depending on a user's role. I would use the Visible property, but there are so many of them, I just decided to do inline C# to show and hide (I know, not best practice, but bear with me for a second). I am having an issue where Page.IsValid is always set to False when I submit my form (when certain fields are being hidden). Will the validations still fire off even if the controls are not even rendered on the pag? Also, if this is not the case, is there an effective way of breaking down Page.IsValid to find out what is setting it to False? Thanks.

推荐答案

如果你设置可见为false,该控件将不可以火验证。从 ASP.Net验证在深度

If you set Visible to false, validation for that control will not fire. From ASP.Net Validation in Depth:

为什么不直接使用可见=假有
  一个无形的验证?在ASP.NET中
  控件的Visible属性有
  很强的含义:与控制
  可见= false将不会被处理时
  一切为pre-渲染或渲染。如
  这种更强意义的结果,
  可见=虚假的验证手段
  这不但没有它不显示
  什么,那就是没有的功能
  无论是。它不评估,不
  影响页面的有效性,并且不把
  错误的摘要。

Why not just use Visible=false to have an invisible validator? In ASP.NET the Visible property of a control has a very strong meaning: a control with Visible=false will not be processed at all for pre-rendering or rendering. As a result of this stronger meaning, Visible=false for a validator means that not only does not it not display anything, it is does not function either. It is not evaluated, does not affect page validity, and does not put errors in the summary.

如果你想有一个控件来验证但它隐藏在页面上,使用CSS来设置显示为无。

If you want a control to validate but have it hidden on the page, use CSS to set display to none.

这篇关于请验证还是在火灾ASP.NET即使控件被隐藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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