什么是Page.IsValid属性的用途 [英] What is use of Page.IsValid Property

查看:109
本文介绍了什么是Page.IsValid属性的用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (Page.IsValid)
            {
                lblTxt.Text = "Page is Valid";
            }
            else
            {
                lblTxt.Text = "Page is not Valid";
            }

推荐答案

来自MSDN [ ^ ]:



此属性返回true,全部当前验证组中的验证服务器控件必须成功验证。只有在调用Page.Validate方法后才能检查此属性,或者在启动表单的ASP.NET服务器控件的OnServerClick事件处理程序中将CausesValidation属性设置为true这些服务器控件包括Button,HtmlButton,HtmlInputButton,HtmlInputImage,ImageButton和LinkBut​​ton类。



如果使用Validate方法强制验证验证组,那么指定验证组中的所有验证控件也必须成功验证。




因此,如果您想知道您的验证是否有效,请检查该属性。
From MSDN[^]:

"For this property to return true, all validation server controls in the current validation group must validate successfully. You should check this property only after you have called the Page.Validate method, or set the CausesValidation property to true in the OnServerClick event handler for an ASP.NET server control that initiates form processing. These server controls include the Button, HtmlButton, HtmlInputButton, HtmlInputImage, ImageButton, and LinkButton classes.

If you force validation of a validation group using the Validate method, then all validation controls in the specified validation group must validate successfully as well."


So, if you want to know if your validation worked, check the property.


这篇关于什么是Page.IsValid属性的用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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