2012-02-13 156 views
0

我在IE8的這一行javascript中收到錯誤消息。當ValidationSummary被註釋掉時不會發生。我相信這是由控件生成的代碼。驗證摘要javascript錯誤

ValidationSummary位於用於asp.net中內容頁面的UserControl上。

當我使用IE瀏覽器的開發工具也突出了這種代碼

document.getElementById('ctl00_ctl00_body_pageBody_ucCC1_valSummary').dispose = function() { 
    Array.remove(Page_ValidationSummaries, document.getElementById('ctl00_ctl00_body_pageBody_ucCC1_valSummary')); 
} 
(function() {var fn = function() {Sys.Extended.UI.ModalPopupBehavior.invokeViaServer('ctl00_ctl00_body_pageBody_mdlPopupExtender', true); Sys.Application.remove_load(fn);};Sys.Application.add_load(fn);})() 




<asp:ValidationSummary 
runat="server" 
ID="valSummary" 
ShowSummary="true" 
DisplayMode="BulletList" 
CssClass="summaryValidation" 
HeaderText="Errors:" 
ForeColor="White" 
ValidationGroup="VldGrpHospital" /> 
+0

@GrailsGuy(可能還有其他人),我猜沿_TypeError線的東西:(中間值)(...)不是一個函數。或者至少這是我通過擁有一個ASP.NET'ValidationSummary'控件並嘗試顯示一個'ModalPopupExtender'控件(Ajax控件工具包)的經驗。 – WynandB 2013-10-09 04:42:16

回答

1

原來這是在AJAX控件工具包一個已知的bug。他們聲稱它已在最新版本中得到修復,但我認爲它沒有。解決方法是創建一個從驗證摘要繼承的服務器控件,並在兩個javascript語句之間插入一個缺少的分號。

http://ajaxcontroltoolkit.codeplex.com/workitem/27024

[ToolboxData("")] 
public class AjaxValidationSummary : ValidationSummary 
{ 
    protected override void OnPreRender(EventArgs e) 
    { 
     base.OnPreRender(e); 
     ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID, ";", true); 
    } 
} 
0

此錯誤是驗證的部分控制在ASP.NET,而不是AJAX工具包。您可以使用EnableClientScript="false"關閉頁面上所有驗證控件的客戶端驗證,錯誤將會消失。

+0

我不確定,除非我們正在討論完全不同的錯誤。正如我在使用舊版本的Ajax Control Toolkit進行測試時不會得到[相同的] JavaScript錯誤一樣。儘管在控件上設置了「EnableClientScript =」False「」。 – WynandB 2013-10-09 04:47:54

0

我在Windows 7上有同樣的問題。這個問題的原因是沒有Windows的最新更新(可能.NET是過時的)。 (我已經自動關閉更新)。安裝更新後,問題解決了

0

有同樣的問題,但對於一個完全地不同的原因,有這個代碼:

<% if(showvalidators){ %> 
<tr> 
    <td> 
    <asp:ValidationSummary ID="SummaryValidator" runat="server" ForeColor="Red" EnableClientScript="true" DisplayMode="BulletList" ShowMessageBox="false" HeaderText="" /> 
    </td> 
</tr> 
<%}%> 

我必須明確禁用ValidationSummaryControl服務器端,如果showvalidator是假的。 Javascript驗證碼嘗試查找summarycontrol(getelementbyid),但未在頁面中呈現。 Enableclientsidescript =「false」可以解決此問題,因爲沒有javascriptcode正在查找丟失的控件。我想這個行爲是在.NET 4.5中爲ValidationSummaryControl提出的,所以這個問題只發生在.NET 4.0中。

1

雖然它可行,但接受的答案可能不是最好的解決方案,因爲它依賴於腳本塊註冊順序匹配輸出順序,這不是一件好事情依賴。從MSDN頁面RegisterStartupScript

Startup script blocks that are registered by using RegisterStartupScript are not guaranteed to be output in the same order in which they are registered. If the order of the startup script blocks is important, use a StringBuilder object to gather the script blocks in a single string, and then register them all as a single startup script.

這裏可能是一個有更好的解決辦法:

public class ValidationSummarySansBug : ValidationSummary 
{ 
    // The bug is that the base class OnPreRender renders some javascript without a semicolon. 
    // This solution registers an almost-identical script *with* a semicolon using the same type and key and relies on the 
    // behavior of ClientScriptManager.RegisterStartupScript to ignore duplicate script registrations for the same type/key 
    protected override void OnPreRender(EventArgs e) 
    { 
     if (Enabled) 
     { 
      ScriptManager.RegisterStartupScript(
       this, 
       typeof(ValidationSummary), // this type must match the base type's specified type for the script we're fixing 
       ClientID + "_DisposeScript", // this key must match the base type key for the script we're fixing 
       @" 
document.getElementById('{0}').dispose = function() {{ 
    Array.remove(Page_ValidationSummaries, document.getElementById('{0}')); 
}}; 
      ".FormatInvariant(ClientID), 
       true); 
     } 

     base.OnPreRender(e); 
    } 
}