0

我正在为 sharepoint 2010 编码。根据这个msdn,当您查看浏览器的页面源代码时,您应该找到类似的内容以使用验证库。我没有找到它。

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

我很困惑,你能解释一下验证库是如何加载到客户端浏览器的吗?

4

1 回答 1

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;");
}
于 2013-01-16T16:34:54.493 回答