Posts

Showing posts from May, 2009

4 Checkboxes – Some tricky issue

Image
Today, almost more than 4 hrs I'd spent on this issue. Do you want to know what is that? Here is that. I have 4 checkbox elements and I have to do the following conditions Condition 1) Any one check box has to selected Condition 2) If any of the first 2 check boxes are selected, my code should throw an exception when the 3rd check box is selected Condition 3) vice versa for Condition 2 A picture is worth of 1000 words. Here is the actual requirement. Hope you got the actual picture. Now here comes the actual twist. You can do that with simple if conditions, but i thought of implementing this using territory operators using a single if condition. And the condition goes like this.. if (((cbRepair1.Checked || cbCalibration1.Checked ) ? (cbBoth1.Checked) ? false : true : (cbBoth1.Checked || cbOnLine1.Checked) ? true : false )== false ){ throw new Exception ( "Duplicate selection .." ); } It took me almost more than 4 hrs. Isn’t it funny!!

CheckBoxList validation

Within our current project, we faced a requirement such that there are multiple checkboxes and the user is required to select any one of them (at least one of them). So as there are multiple checkboxes, decided to go with CheckBoxList control. Now the problem is that, we need to show a error message if the user is not selected any one of them. The problem also extends not just there, but the display text should be culture specific. So the story started long after I've written this post. But editing this entire post due to a simple non supportive feature by IE. I’ll come to that point little later, let me first detail the requirement and solution. There is one more solution for this unsupported error. Please read thru the post. For all the client side validations, it is widely known that validation controls supported by ASP.NET framework are popularly used. But these controls can’t handle the CheckBoxList. Hence the following solution. Step 1: Place your CheckBoxList control in a