Показват се публикациите с етикет WAI. Показване на всички публикации
Показват се публикациите с етикет WAI. Показване на всички публикации

ASP.NET LinkButton - when disabled renders not a valid xHTML.

четвъртък, 26 юли 2007 г.

What is the problem with LinkButton control in ASP.NET?
When you disable a LinkButton i.e. set Enabled="false", ASP.NET renders disabled="disabled" which is not a valid xHTML property.

How we can fix this?
If you view the source code of the LinkButton control and more specific the AddAttributesToRender method, you will notice that it adds the disabled attribute when Enabled is set to false. The second thing you will see there is that no matter you have set or not the PostBackUrl property to string.Empty, the method renders href property and link postbacks i.e. every time when the LinkButton is Enabled.

So what functionality does we have to achieve? When the LinkButton is disabled, we get these five things:

0. Get rid of the disabled="disabled" property.
1. The link must not be clickable (=> there will be no postback).
2. The cursor is not a hand, but as the thing under is simple text (=> the user will not expect that it is clickable ).
3. We have no underlining.
4. The color is grey as a disabled link. Here I'll add, that if you want to make it more flexible for design, you can set a css class name in which designers can add the appropriate color.

Therefore the thing which will have to do are respectively:
0. Set control's Enabled property to true.
1. Set the PostBackUrl to javascript:void(0).
2. Set the cursor to be of type text.
3. Set the text-decoration to none.
4. Set the color to grey.

As in my previous post which you can find here, we will achieve this with the help of control adapters. Here is a sample source code:



Conclusion
This solution shows again the power of control adapters - properly rendered controls of some type in the whole web site just with a few lines of code.

ASP.NET CheckBox - rendering not compatible with WAI.

събота, 14 юли 2007 г.

What is WAI?
WAI stands for Web Accessibility Initiative. It's an attempt of W3C to improve the accessibility of WWW with different user agent devices which is especially important for people with physical disabilities. WAI is an number of guidelines that can help to make WWW more accessible. For more information look at here.

What is the problem with CheckBox control in ASP.NET?
The problem is that WAI suggests that controls such as text boxes, images, buttons etc. must have tooltips. So when you add a ToolTip property of a asp:CheckBox control, ASP.NET renders wrapping span and set's the tooltip to the span. But as I mentioned above WAI requires an alt(title) tag for every INPUT and when you try to validate a page with a checkbox the validation will fail.

How we can fix this?
As my friend and colleague Stefan Dobrev recently rightly pointed, Microsoft ASP.NET Team done their work excellent and in ASP.NET 2.0 they have provided very elegant solution for such problems - Control Adapters. (For more information about the architecture of control adapters look at this post)

To use control adapter, we have to create the standard folder named App_Browsers and in it we have to add a file with extension .browser - the so called Browser definition file. This is the content of the file in my example:



In the file we add section in which we add an adapter for control of type System.Web.UI.WebControls.CheckBox and we associated the adapter CheckBoxCtrlAdapter which is defined as below:


Thus all of the checkboxes in your page will render WAI compatible.

Conclusion
For many people WAI is very restrictive and in some ways hard achievable and even unnecessary. I think that at least easily achievable features should be observed. The future will show whether WAI will become a wide spred standard.

 
Vesko Kolev's Blog : IDeveloper -