xingd.net

.net related techonology

导航

ASP.NET 1.1无法提交的问题

Posted on 2005-02-25 17:22  xingd  阅读(4779)  评论(6编辑  收藏  举报
     今天在产品里发现了一个bug,多个aspx页面都无法提交,点了提交按纽都没有反应,初步猜测是Validate的问题。详细的解决过程就不写了,将最后的结论总结如下:

    .NET Framework 1.1的补丁对Validator有影响,如果使用补丁前的WebUIValidation.js,会导致包含有Validators的页面无法提交。

     打补丁前,WebUIValidation.js中的ValidatorCommonOnSubmit如下:
function ValidatorCommonOnSubmit() {
    
event.returnValue = !Page_BlockSubmit;
    Page_BlockSubmit 
= false;
}

  打补丁后,ValidatorCommonOnSubmit如下:
 
function ValidatorCommonOnSubmit() {
    var result 
= !Page_BlockSubmit;
    Page_BlockSubmit 
= false;
    
event.returnValue = result;
    
return result;
}

 打补丁前,System.Web.dll中BaseValidator的RegisterValidatorCommonScript如下:
protected void RegisterValidatorCommonScript()
{
      
if (this.Page.IsClientScriptBlockRegistered("ValidatorIncludeScript"))
      
{
            
return;
      }

      
string text1 = Util.GetScriptLocation(this.Context);
      
string text2 = HttpRuntime.FormatResourceString("Validator_missing_script", text1 + "WebUIValidation.js");
      
string text3 = HttpRuntime.FormatResourceString("Validator_wrong_script""WebUIValidation.js""125""\" + Page_ValidationVer + \"");
      
string text4 = string.Empty;
      
if (this.Page.Request.IsLocal)
      
{
            
object[] objArray1 = new object[3{ text2, "125", text3 } ;
            text4 
= string.Format("\r\n<script language=\"javascript\">\r\n<!--\r\nvar Page_ValidationActive = false;\r\nif (typeof(clientInformation) != \"undefined\" && clientInformation.appName.indexOf(\"Explorer\") != -1) {{\r\n    if (typeof(Page_ValidationVer) == \"undefined\")\r\n        alert(\"{0}\");\r\n    else if (Page_ValidationVer != \"{1}\")\r\n        alert(\"{2}\");\r\n    else\r\n        ValidatorOnLoad();\r\n}}\r\n\r\nfunction ValidatorOnSubmit() {{\r\n    if (Page_ValidationActive) {{\r\n        ValidatorCommonOnSubmit();\r\n    }}\r\n}}\r\n// -->\r\n</script>\r\n        ", objArray1);
      }

      
else
      
{
            text4 
= string.Format("\r\n<script language=\"javascript\">\r\n<!--\r\nvar Page_ValidationActive = false;\r\nif (typeof(clientInformation) != \"undefined\" && clientInformation.appName.indexOf(\"Explorer\") != -1) {{\r\n    if ((typeof(Page_ValidationVer) != \"undefined\") && (Page_ValidationVer == \"{0}\"))\r\n        ValidatorOnLoad();\r\n}}\r\n\r\nfunction ValidatorOnSubmit() {{\r\n    if (Page_ValidationActive) {{\r\n        ValidatorCommonOnSubmit();\r\n    }}\r\n}}\r\n// -->\r\n</script>\r\n        ""125");
      }

      
this.Page.RegisterClientScriptFileInternal("ValidatorIncludeScript""javascript", text1, "WebUIValidation.js");
      
this.Page.RegisterStartupScript("ValidatorIncludeScript", text4);
      
this.Page.RegisterOnSubmitStatement("ValidatorOnSubmit""ValidatorOnSubmit();");
}

  打完补丁后,RegisterValidatorCommonScript代码如下:
protected void RegisterValidatorCommonScript()
{
      
if (this.Page.IsClientScriptBlockRegistered("ValidatorIncludeScript"))
      
{
            
return;
      }

      
string text1 = Util.GetScriptLocation(this.Context);
      
string text2 = HttpRuntime.FormatResourceString("Validator_missing_script", text1 + "WebUIValidation.js");
      
string text3 = HttpRuntime.FormatResourceString("Validator_wrong_script""WebUIValidation.js""125""\" + Page_ValidationVer + \"");
      
string text4 = string.Empty;
      
if (this.Page.Request.IsLocal)
      
{
            
object[] objArray1 = new object[3{ text2, "125", text3 } ;
            text4 
= string.Format("\r\n<script language=\"javascript\" type=\"text/javascript\">\r\n<!--\r\nvar Page_ValidationActive = false;\r\nif (typeof(clientInformation) != \"undefined\" && clientInformation.appName.indexOf(\"Explorer\") != -1) {{\r\n    if (typeof(Page_ValidationVer) == \"undefined\")\r\n        alert(\"{0}\");\r\n    else if (Page_ValidationVer != \"{1}\")\r\n        alert(\"{2}\");\r\n    else\r\n        ValidatorOnLoad();\r\n}}\r\n\r\nfunction ValidatorOnSubmit() {{\r\n    if (Page_ValidationActive) {{\r\n        return ValidatorCommonOnSubmit();\r\n    }}\r\n    return true;\r\n}}\r\n// -->\r\n</script>\r\n        ", objArray1);
      }

      
else
      
{
            text4 
= string.Format("\r\n<script language=\"javascript\" type=\"text/javascript\">\r\n<!--\r\nvar Page_ValidationActive = false;\r\nif (typeof(clientInformation) != \"undefined\" && clientInformation.appName.indexOf(\"Explorer\") != -1) {{\r\n    if ((typeof(Page_ValidationVer) != \"undefined\") && (Page_ValidationVer == \"{0}\"))\r\n        ValidatorOnLoad();\r\n}}\r\n\r\nfunction ValidatorOnSubmit() {{\r\n    if (Page_ValidationActive) {{\r\n        return ValidatorCommonOnSubmit();\r\n    }}\r\n    return true;\r\n}}\r\n// -->\r\n</script>\r\n        ""125");
      }

      
this.Page.RegisterClientScriptFileInternal("ValidatorIncludeScript""javascript", text1, "WebUIValidation.js");
      
this.Page.RegisterStartupScript("ValidatorIncludeScript", text4);
      
this.Page.RegisterOnSubmitStatement("ValidatorOnSubmit""if (!ValidatorOnSubmit()) return false;");
}

  花了些时间找出问题原因,记录下来,以便查询。

  再有就是建议没有打.NET Framework 1.1补丁的,尽早打补丁,同时不要在发布产品的时候发布任何.NET Framework中带的文件,包含.js和.dll。