This post covers Crystal Reports.NET v11 (the version that comes with Visual Studio.NET 2008), and ASP.NET.
WCAG stands for Web Content Accessibility Guidelines, but chances are if you found this blog post, you already know that. If you want to know more about WCAG compliance, here’s the complete run-down straight from the World Wide Web Consortium (W3C):
http://www.w3.org/TR/WCAG10/. This post will not get into the intricacies of WCAG compliance, but merely gives a couple small steps to help in achieving it.
I’m currently working on achieving WCAG compliance within several of the ASP.NET web applications I have developed. During my progress, I have discovered that the ASP.NET Crystal Reports.NET Report Viewer Control is not WCAG compliant. This article will show you how to manipulate the Report Viewer Control in order to reach a level of basic compliance.
Problem 1: The button images in the toolbar do not contain alternate text properties (alt), however, they do contain tooltip properties (title tags). Since the toolbar buttons have titles but not alternative text, we can simply take the title string from each toolbar button and apply it to each of the buttons alternate text property. We can achieve this by recursively parsing through the Report Viewer Control, finding the image buttons, and changing their alternative text to equal that of the tooltip text. Always manipulate your Report Viewer Control in the Init event handler. Here's the code:
Imports System.Web.UI.WebControls
Imports System.Web.UI
Imports System.IO
Imports System.Text
Partial Public Class MyPage
Inherits Page
Protected Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)
AddButtonAltText(MyCrystalReportsViewer)
End Sub
Protected Sub AddButtonAltText(ByVal oCntrl As Control)
Dim oButton As ImageButton = Nothing
For Each oChildCntrl As Control In oCntrl.Controls
If TypeOf oChildCntrl Is ImageButton Then
oButton = DirectCast(oChildControl, ImageButton)
If (oButton.AlternateText = "") Then
oButton.AlternateText = oButton.ToolTip
End If
Else
If oChildCntrl.Controls.Count > 0 Then
AddToolBarButtonAltText(oChildCntrl)
End If
End If
Next
End Sub
End class
Problem 2: The Crystal Reports.NET Report Viewer Control renders useless non-WCAG-compliant HTML. The useless HTML rendered by control appears to be a bookmark, with a link to that bookmark that will send the page down to the Report Viewer Control upon clicking it. The bookmark link is one line above the control, so what's the point in this anyway? Plus the link has no text, a link without text breaks WCAG compliancy, and what good is a link without text anyway? I spent hours trying to figure out how to give the link text, or remove the bookmark and link entirely, but have had no luck. Contact me if you know how to do any of this. Here’s the useless HTML that’s generated:
<A HREF="#page" TITLE="Go to Report Page Content"></A>
A couple lines down from that:
Here's how to remove the useless HTML. I have determined that there is no property or method to remove this HTML, so I had to resort to removing the HTML manually after the Page's HTML has been rendered. Here's the code:
Imports System.Web.UI.WebControls
Imports System.Web.UI
Imports System.IO
Imports System.Text
Partial Public Class MyPage
Inherits Page
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
Dim sNewHTML As StringBuilder = New StringBuilder("")
Dim sNewStringWriter As StringWriter = New StringWriter(sNewHTML)
Dim sNewHTMLWriter As HtmlTextWriter = New HtmlTextWriter(sNewStringWriter)
MyBase.Render(sNewHTMLWriter)
writer.Write(StripUselessRenderedHTML(sNewHTML.ToString()))
End Sub
Protected Function StripUselessRenderedHTML(ByVal sHTML As String) As String
sHTML = sHTML.Replace("<A HREF=""#page"" TITLE=""Go to Report Page Content""></A>", "")
sHTML = sHTML.Replace("<A NAME=""page""></A>", "")
Return sHTML
End Function
End Class
You will probably want to combine these two page classes above into one page class. I divided them only to try to improve readibilty.
Here are some great plugins for FireFox that will check your rendered HTML for WCAG compliancy.
WAVE:
http://wave.webaim.org/toolbar/
HTML Validator:
https://addons.mozilla.org/en-US/firefox/addon/249/
Also, don’t forget about about your web accesibility tool in Visual Studio!
Finally, if your page achieves a basic level of WCAG compliancy, your page will also most likely pass W3C validation as well.
Tags: asp.net,
crystal reports.net
Categories: Crystal Reports.NET |
ASP.NET
3ede073b-4fa3-4161-b596-6f62a8c57354|0|.0