我正在为 sharepoint 2010 编码。根据这个msdn,当您查看浏览器的页面源代码时,您应该找到类似的内容以使用验证库。我没有找到它。
<script language="javascript"
src="/aspnet_client/system_web/1_0_3617_0/WebUIValidation.js">
</script>
我很困惑,你能解释一下验证库是如何加载到客户端浏览器的吗?
我正在为 sharepoint 2010 编码。根据这个msdn,当您查看浏览器的页面源代码时,您应该找到类似的内容以使用验证库。我没有找到它。
<script language="javascript"
src="/aspnet_client/system_web/1_0_3617_0/WebUIValidation.js">
</script>
我很困惑,你能解释一下验证库是如何加载到客户端浏览器的吗?
该WebUIValidation.js
文件包含用于客户端验证的客户端 JavaScript 函数。它会在以下情况下自动注入页面:
我启动了 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;");
}