ASP.NET events can cause troubles

...if you are developing a Webrichtlijnen compliant website in ASP.NET or let's say in... SharePoint 2007!

Recently a new version of the Webrichtlijnen on-line quick scan tool has been released. Not that long ago I have reported that my concept on making SharePoint 2007 sites 100% Webrichtlijnen compliant did work. As soon as I have checked the same code using the newer version of the quick scan tool I have found there were still some errors present in the website.

These errors are JavaScript events related and these are attached to the ASP.NET controls. Let me explain it to you by using an ASP.NET button as an example.

So let's say you're making a custom search Web Part: a text field to enter the search query and a button to run the search. Using the ASP.NET events concept you create a new OnClick event for the button and you attach it to your button. What ASP.NET does is it creates a JavaScript onclick event and attaches it to the output. What you see in the source code of the rendered page is something like <input type="button" onclick=".... Why is this a problem?

Conform the Webrichtlijnen you are supposed to be using non-obtrusive JavaScript. Any in-line events are therefore forbidden. An onclick attached to a button or any other control is a no-go. But does it mean you cannot use these events at all? Well, it depends. If you're building a quite simple Web Part like the one above you could use one of the Web Part's methods triggered on postback instead and then check the value of the textbox. Another option would be catching the ASP.NET output and rewriting the inline events with their unobtrusive equivalents - I really wish you success with this one though.

Both server- and client-side events in ASP.NET are definitely something to take into consideration while developing Webrichtlijnen compliant websites. As Internet facing websites based on SharePoint 2007 are most of the times highly customized you as developer are in control of the output and the way you implement your business logic into the custom control. It is doable but it requires some more creativity than a regular SharePoint solution.


comments powered by Disqus