2010-04-15 26 views
1

我們在ASP.Net MVC項目中使用Telerik Rad Controls for ASP.Net Ajax。所述RadChart生成以下HTML:如何防止Telerik RadChart生成onerror屬性?

<img onerror="if(confirm('Error loading RadChart image.\nYou may also wish to check the ASP.NET Trace for further details.\nDisplay stack trace?'))window.location.href=this.src;" src="ChartImage.axd?UseSession=true&amp;ChartID=e25ad666-e05b-4a92-ac0c-4f2c729b9382_chart_ctl00$MainContent$AverageCTMChart&amp;imageFormat=Png&amp;random=0.501658702968461" usemap="#imctl00_MainContent_AverageCTMChart" style="border-width: 0px;" alt=""> 

我想除去onerror屬性;如果出現問題,我不希望客戶提供選項來查看堆棧跟蹤。我看不到任何方法來控制此控件生成的標記。谷歌搜索沒有提供幫助。有沒有人處理過這個?

如何刪除onerror屬性?

回答

1

onerror只在調試配置中才顯示。一旦你在Release中部署你的應用程序,該屬性不會被渲染!

+0

好交易。這是記錄在任何地方,或者你只需​​要知道它? – 2010-06-26 05:01:58

0

你可以做這樣的事情,只需將它添加到頁面底部或在某處加載事件中調用removeOnError即可。

function removeOnError(){ 
    //Grab all images 
    var imgs = document.getElementsByTagName('img'); 
    for(var i=0;i<imgs.length;i++){ 
     //If they've got the onerror attribute 
     if(imgs[i].onerror){ 
      //set it to null 
      imgs[i].onerror = null; 
     } 
    } 
} 
//Call the function above 
removeOnError(); 

編輯

看Telerik的網站就不會出現一個選項,以便我能想到的唯一的辦法就是重寫Render事件爲您的網頁,並手動撕出來:

protected override void Render(HtmlTextWriter writer) 
{ 
    using (System.IO.MemoryStream MS = new System.IO.MemoryStream()) 
    { 
     using (System.IO.StreamWriter SW = new System.IO.StreamWriter(MS)) 
     { 
      HtmlTextWriter NW = new HtmlTextWriter(SW); 
      base.Render(NW); 
      NW.Flush(); 
      MS.Position = 0; 
      using (System.IO.StreamReader SR = new System.IO.StreamReader(MS)) 
      { 
       string html = SR.ReadToEnd(); 
       MatchCollection MC = Regex.Matches(html, "<img.*?(?<OnError>onerror=\".*?\").*?>"); 
       foreach (Match M in MC) 
       { 
        if (M.Success) 
        { 
         html = html.Replace(M.Groups["OnError"].Value, ""); 
        } 
       } 
       Response.Write(html); 
       SR.Close(); 
      } 
     } 
    } 
} 
+0

我真的不想把它放在首位。如果圖像錯誤,它可能會在加載事件之前觸發onerror事件,這意味着將其刪除將爲時太晚。 – 2010-04-15 14:29:44

+0

你可以重寫MVC應用程序中的渲染嗎? – 2010-04-15 16:04:55

+0

我沒有任何地方運行的MVC網站,但我相信你會在視圖引擎中重寫RenderView,http://msdn.microsoft.com/zh-CN/library/system.web.mvc.viewpage.renderview.aspx – 2010-04-15 16:47:28

0

Telerik控制檢查物業

HttpContext.Current.IsDebuggingEnabled 

,以決定是否產生onerror的屬性。因此,要刪除這些塊,確保調試在您的web.config中的「編譯」節點關閉

<compilation debug="false">