<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Chakravarthy's Space : .NET</title><link>http://msmvps.com/blogs/chakravarthy/archive/tags/.NET/default.aspx</link><description>Tags: .NET</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>CheckBoxList validation</title><link>http://msmvps.com/blogs/chakravarthy/archive/2009/05/21/checkboxlist-validation.aspx</link><pubDate>Thu, 21 May 2009 05:04:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1692892</guid><dc:creator>Chakravarthy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/rsscomments.aspx?PostID=1692892</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/commentapi.aspx?PostID=1692892</wfw:comment><comments>http://msmvps.com/blogs/chakravarthy/archive/2009/05/21/checkboxlist-validation.aspx#comments</comments><description>&lt;p&gt;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.&lt;/p&gt;  &lt;p&gt;So the story started long after I&amp;#39;ve written this post. But editing this entire post due to a simple non supportive feature by IE. I’ll come to that point later in this post, let me first detail the requirement and solution. There is one more solution for this unsupported error. Please read thru the post.&lt;/p&gt;  &lt;p&gt;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.&lt;/p&gt;  &lt;p&gt;Step 1: Place your CheckBoxList control in a separate div as shown below. Observe that the text for these controls are populated from database depending upon the user culture&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;div &lt;/span&gt;&lt;span style="color:red;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;cblItems1&amp;quot;&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;CheckBoxList &lt;/span&gt;&lt;span style="color:red;"&gt;ID&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;cblOptions&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;runat&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;server&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;$Resources:CommonFormFields, Repair&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;$Resources:CommonFormFields, Calibration&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;$Resources:CommonFormFields, RepairCalibration&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;$Resources:CommonFormFields, OnlineService&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListItem&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;CheckBoxList&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;div&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Step 2: Use ASP:Lable and get the error message while loading and place in a separate div and hide this div by default as mentioned below. Please note the div ID as &lt;font color="#0000ff"&gt;cblError1&lt;/font&gt; and the style is set to hidden by default&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;div &lt;/span&gt;&lt;span style="color:red;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;cblError1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;style&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color:red;"&gt;visibility&lt;/span&gt;: &lt;span style="color:blue;"&gt;hidden&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label &lt;/span&gt;&lt;span style="color:red;"&gt;ID&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;lblReq1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;runat&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;server&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="background:#ffee62;"&gt;&amp;lt;%&lt;/span&gt;$Resources:CommonFormFields, SelectAny&lt;span style="background:#ffee62;"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Label&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;div&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Step 3: Write a JScript function that reads all the client side rendered elements as &lt;font color="#0000ff"&gt;input&lt;/font&gt; objects and checks whether any of them are checked or not. Code explains more in detail&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;function &lt;/span&gt;CheckListValidation(cblItm, errDiv)
{
&lt;span style="color:green;"&gt;    &lt;/span&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;tDiv = document.getElementById(cblItm);
    &lt;span style="color:blue;"&gt;var &lt;/span&gt;chkitems = tDiv.childNodes[1];
    &lt;span style="color:blue;"&gt;var &lt;/span&gt;chkitm = chkitems.getElementsByTagName(&lt;span style="color:#a31515;"&gt;&amp;quot;input&amp;quot;&lt;/span&gt;);
    &lt;span style="color:blue;"&gt;for &lt;/span&gt;(&lt;span style="color:blue;"&gt;var &lt;/span&gt;i = 0; i &amp;lt; chkitm.length; i++) 
    {
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(chkitm.checked) 
        {                    
                &lt;span style="color:blue;"&gt;return true&lt;/span&gt;;
        }
    }
    document.getElementById(errDiv).style.visibility = &lt;span style="color:#a31515;"&gt;&amp;#39;visible&amp;#39;&lt;/span&gt;;
    &lt;span style="color:blue;"&gt;return false&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Step 4: Now it is the turn of invoking this function from the button click. Every button is having a method called as “OnClientClick” along with Click. Invoke this function from that method as mentioned below&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;asp&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Button &lt;/span&gt;&lt;span style="color:red;"&gt;ID&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;btnAddMore&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;runat&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;server&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Add More&amp;quot; 
&lt;/span&gt;&lt;span style="color:red;"&gt;OnClientClick&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;return CheckListValidation(&amp;#39;cbOptions&amp;#39;,&amp;#39;cblError1&amp;#39;);&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;OnClick&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;btnAddMore_Click&amp;quot; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Step 5: All setup and the code is running fine. But there is a problem with this code while running in IE. IE 6 and above doesn’t support the getElementsByTag &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;vTe = document.getElementsByTagName(..);&lt;/pre&gt;
There is a long story for this. Let me post one more post for the better mechanism of CheckBoxList Validation. Until then, what are your comments?? 

&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1692892" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Tips/default.aspx">Tips</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/Code/default.aspx">Code</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/.NET/default.aspx">.NET</category></item><item><title>.NET 4.0 &amp; VS 2010 CTP is Ready</title><link>http://msmvps.com/blogs/chakravarthy/archive/2008/11/21/net-4-0-amp-vs-2010-ctp-is-ready.aspx</link><pubDate>Fri, 21 Nov 2008 03:41:15 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1654723</guid><dc:creator>Chakravarthy</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/rsscomments.aspx?PostID=1654723</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/chakravarthy/commentapi.aspx?PostID=1654723</wfw:comment><comments>http://msmvps.com/blogs/chakravarthy/archive/2008/11/21/net-4-0-amp-vs-2010-ctp-is-ready.aspx#comments</comments><description>&lt;p&gt;Ofcourse, i might sound late in this announcement, but better late than never. On 31st October 2008, Microsoft has announced the CTP version of Visual Studio 2010 and Framework version 4.0. And their statement goes like this.&lt;/p&gt; &lt;p&gt;Visual Studio 2010 and the .NET Framework 4.0 mark the next generation of developer tools from Microsoft. Designed to address the latest needs of developers, Visual Studio delivers key innovations in the following pillars:&lt;br /&gt;&lt;b&gt;Democratizing Application Lifecycle Management&lt;/b&gt;&lt;br /&gt;Application Lifecycle Management (ALM) crosses many roles within an organization and traditionally not every one of the roles has been an equal player in the process. Visual Studio Team System 2010 continues to build the platform for functional equality and shared commitment across an organization’s ALM process.&lt;br /&gt;&lt;b&gt;Enabling emerging trends&lt;/b&gt;&lt;br /&gt;Every year the industry develops new technologies and new trends. With Visual Studio 2010 and .NET Framework 4.0, Microsoft delivers tooling and framework support for the latest innovations in application architecture, development and deployment.&lt;br /&gt;&lt;b&gt;Inspiring developer delight&lt;/b&gt;&lt;br /&gt;Ever since the first release of Visual Studio, Microsoft has set the bar for developer productivity and flexibility. Visual Studio 2010 continues to deliver on the core developer experience by significantly improving upon it for roles involved with the software development process. .NET Framework 4.0 contains numerous improvements that make it easier to develop powerful and compelling applications.&lt;br /&gt;&lt;b&gt;Riding the next generation platform wave&lt;/b&gt;&lt;br /&gt;Microsoft continues to invest in the market leading operating system, productivity application and server platforms to deliver increased customer value in these offerings. With Visual Studio 2010 and .NET Framework 4.0 customers will have the tooling support and the platform support needed to create amazing solutions around these technologies.  &lt;p&gt;Find the same and download from &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=922b4655-93d0-4476-bda4-94cf5f8d4814&amp;amp;displaylang=en&amp;amp;tm#filelist"&gt;this link&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1654723" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/VisualStudio/default.aspx">VisualStudio</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/News/default.aspx">News</category><category domain="http://msmvps.com/blogs/chakravarthy/archive/tags/.NET/default.aspx">.NET</category></item></channel></rss>