使用RequiredFieldValidator - 因此,如果已禁用Javascript整个.NET控件是可以避免的?控件、RequiredFieldValidator、Javascript、NE

2023-09-03 04:17:38 作者:安好勿扰

我使用.NET最近,我查了一些领域。

I'm using .NET recently, and I check some fields.

我知道检查客户端(JavaScript)和服务器端的使用:

I know that the check is client-side (javascript) and on server-side with :

Page.Validate();

if (!Page.IsValid)
{
}

但是,如果禁用JavaScript个个都没有检查(事实上的JavaScript返回false当我尝试做的请求到服务器。

But if the javascript is disabled all of them are not checked (in fact the javascript return false when I try to do the request to the server.

所以,这是对.NET的限制或者有其他的方式做这些检查没有JS?

So, is this a limitation of .NET or there are other way to do these check without JS?

推荐答案

你是对的,使用 Page.IsValid 将只返回正确的值,如果启动Javascript /支持的浏览器。因此,良好的网络编程做法是在服务器端再次运行同样的验证,无论客户端验证的考虑。由于客户端的JavaScript可以在浏览器很容易被改变,以绕过了验证。

You are right, using Page.IsValid will only return correct value if javascript is enabled / supported in the browser. So, good web programming practice is to run same validations again at server side regardless of client side validation consideration. Because client side javascript can be altered easily in browser to bypass that the validations.

这将确保你正在接受正确的价值观。

That will ensure you are accepting correct values.