WebForm Gripe - Getting LinkButton to work without Javascript.
WebForms is a sort of love/hate thing for me. There are some things I love about WebForms and then there's quite a few things that really cause me a lot of pain. Sadly, the ones that cause me a lot of pain are the ones that stand out. I might turn these into a little series - depending on how many of these gripes show up and how many I can remember! Most of these gripes are probably me just not understanding WebForms correctly, I'm willing to learn so any pointers in the right direction would be good.
LinkButton or Button
The first one that I'm going to write about is the LinkButton control. For the most part it's a nice control, which allows a method to be called when a normal anchor link has been clicked. The problem occurs when the method is only called via a Javascript PostBack method in the href attribute. What this does is stop people who do not have Javascript running on their browser (for whatever reason that may be) from using the site.
There's always the argument of 'Why not use a Button control instead of a LinkButton control?' but the truth is a anchor link is much more customisable than a Button field when it comes to CSS or putting content inside of it.
Why should you care?
The reason you should care is that when you have, say, 500,000 people visit your site in a month and you left a LinkButton control as the main submit button for a contact form, if only 0.5% of those people don't have Javascript, then that's potentially 2,500 extra people missing out on submitting their information. It'd be nice to have a real study to show what percentage of people use Javascript but I don't have that, so I'd rather make a site work for everyone and not worry about people having Javascript than have something which only works with Javascript and potentially stop the website from functioning correctly for those people without Javascript.
How do we fix this problem?
The way that I have solved the problem of the LinkButton control is to use the built in noscript tags - which gets rendered when Javascript isn't avaliable. The problem with just using this straight in the code is that you can't have ASP.NET code inside of Javascript tags. One solution by Alex Papadimoulis was to use a control to render the server side code and then display the output with Javascript document.write() methods. Although the control is not perfect, it works pretty well to render out LinkButtons when needed and allows an alternative control, such as the Button control, when Javascript is not avaliable. Although the Button control won't be styled as nice, at least the functionality will still work (just don't show the designers what it looks like without Javascript!).
The code for this control can be found over on Alex Papadimoulis' blog here - http://weblogs.asp.net/alex_papadimoulis/a...noscript.aspx
If anyone has a better solution then it'd be fantastic to hear about it,
Chris