客户端验证库在哪里?

时间:2013-01-16 16:28:31

标签: asp.net sharepoint

我正在编写sharepoint 2010.根据此msdn,当您查看浏览器的页面源时,您应该找到类似这样的内容以便使用验证库。我没找到。

<script language="javascript" 
        src="/aspnet_client/system_web/1_0_3617_0/WebUIValidation.js">
</script>

我很困惑,你能解释如何将验证库加载到客户端浏览器。

1 个答案:

答案 0 :(得分:1)

WebUIValidation.js文件包含用于客户端验证的客户端JavaScript函数。在以下情况下自动注入页面

  • 该页面包含一个或多个验证Web控件。
  • “高级”浏览器正在访问该页面。

我启动了Reflector,在System.Web.UI.WebControls.BaseValidator类中挖掘了一个峰值,该类是从中派生所有验证Web控件的类。 RegisterValidationCommonScript()方法负责。

致记:http://scottonwriting.net/sowblog/archive/2004/11/03/163009.aspx

通过ILSpy(.NET 4.0)反映:

// System.Web.UI.WebControls.BaseValidator
protected void RegisterValidatorCommonScript()
{
    if (this.Page.IsPartialRenderingSupported)
    {
        ValidatorCompatibilityHelper.RegisterClientScriptResource(this, typeof(BaseValidator), "WebUIValidation.js");
        ValidatorCompatibilityHelper.RegisterStartupScript(this, typeof(BaseValidator), "ValidatorIncludeScript", "\r\nvar Page_ValidationActive = false;\r\nif (typeof(ValidatorOnLoad) == \"function\") {\r\n    ValidatorOnLoad();\r\n}\r\n\r\nfunction ValidatorOnSubmit() {\r\n    if (Page_ValidationActive) {\r\n        return ValidatorCommonOnSubmit();\r\n    }\r\n    else {\r\n        return true;\r\n    }\r\n}\r\n        ", true);
        ValidatorCompatibilityHelper.RegisterOnSubmitStatement(this, typeof(BaseValidator), "ValidatorOnSubmit", "if (typeof(ValidatorOnSubmit) == \"function\" && ValidatorOnSubmit() == false) return false;");
        return;
    }
    if (this.Page.ClientScript.IsClientScriptBlockRegistered(typeof(BaseValidator), "ValidatorIncludeScript"))
    {
        return;
    }
    this.Page.ClientScript.RegisterClientScriptResource(typeof(BaseValidator), "WebUIValidation.js");
    this.Page.ClientScript.RegisterStartupScript(typeof(BaseValidator), "ValidatorIncludeScript", "\r\nvar Page_ValidationActive = false;\r\nif (typeof(ValidatorOnLoad) == \"function\") {\r\n    ValidatorOnLoad();\r\n}\r\n\r\nfunction ValidatorOnSubmit() {\r\n    if (Page_ValidationActive) {\r\n        return ValidatorCommonOnSubmit();\r\n    }\r\n    else {\r\n        return true;\r\n    }\r\n}\r\n        ", true);
    this.Page.ClientScript.RegisterOnSubmitStatement(typeof(BaseValidator), "ValidatorOnSubmit", "if (typeof(ValidatorOnSubmit) == \"function\" && ValidatorOnSubmit() == false) return false;");
}