Posted by Ramani Sandeep on February 10, 2010
Every ASP.NET developer needs validation on CheckBoxList that can be one of these two:
- Check for RequiredField
- Check for Maximum Selection Limit
1. Check for RequiredField
I will be using JQuery to interecept the click event of each single Checkbox inside the CheckBoxList and then update a hidden TextBox control which has a RequiredFieldValidator associated to it, when a CheckBox is clicked.
When all CheckBoxes were unselected, the hidden TextBox would have nothing in it which makes the RequiredFieldValidator throws a JavaScript message on Submit.
Listing – 1 : CheckBoxList
<asp:CheckBoxList ID="cblBusinessType" runat="server" CssClass="checkbox" ValidationGroup="VGEdit">
</asp:CheckBoxList>
<asp:Label ID="Label12" runat="server" Text="Select up to 3 Business Types" CssClass="label_black"></asp:Label>
<asp:TextBox ID="txtCheckbox" runat="server" ValidationGroup="testGroup" style='display: none;'/>
<asp:RequiredFieldValidator ID="valCheckboxList" Display="Dynamic"
ErrorMessage="At least one business type must be selected"
runat="server" ControlToValidate="txtCheckbox"
ValidationGroup="VGEdit" EnableClientScript="true" CssClass="ErrorLabel_10"
SetFocusOnError="true"/>
Listing – 2 : jQuery Script for RequiredFieldValidator
<script type="text/javascript">
$(function() {
function checkBoxClicked() {
//Get the total of selected CheckBoxes
var n1 = $("#<%= cblBusinessType.ClientID %> input:checked").length;
//Set the value of the txtCheckbox control
$("input:#<%= txtCheckbox.ClientID %>").val(n1 == 0 ? "" : n1);
}
//intercept any check box click event inside the #list Div
$("#<%= cblBusinessType.ClientID %> :checkbox").click(checkBoxClicked);
});
</script>
2. Check for Maximum Selection Limit
We also often need to check that user can select only n items from the checkboxlist. so for that I have anothe jQuery script that help the developer to restrict the user from selection after he reach the max limit.
Listing – 3 : jQuery Script for Maximum Selection Limit
<script type="text/javascript" language="javascript">
//Count the Total Selection in CheckBoxList - BusinessType
$('#<%= cblBusinessType.ClientID %>').find('input:checkbox').click(function()
{
var totCount=0;
jQuery('#<%= cblBusinessType.ClientID %>').find("input:checkbox").each(function() {
if (jQuery(this).attr("checked"))
{
totCount++;
}
});
if(totCount > 3)
{
alert("Select up to 3 Business Types only...");
return false;
}
return true;
});
</script>
Here in this function I have counted each selected checkbox by using jQuery selector each time user check/uncheck the checkbox. once the count goes beyond the limit flag the error message to user to remind that you have crossed the limit.
Hope this will Help
Jay Ganesh
23.052108
72.533442
Posted in JQuery | Tagged: CheckBoxList client side validation using JQuery, CheckBoxList validation, CheckBoxList validation using JQuery | Leave a Comment »
Posted by Ramani Sandeep on February 8, 2010
This post is a tutorial on how to create a web-service which can be called from java-script and then continues on to show you how to use it with the Virtual Earth map control.
Read more
Hope this helps

Posted in ASP.NET 3.5, Web Services | Tagged: Using Virtual Earth control with a Web-Service, Virtual Earth | Leave a Comment »
Posted by Ramani Sandeep on February 8, 2010
SQL is a declarative language, designed to work with sets of data. However, it does support procedural, "row-by-row" constructs in the form of explicit cursors, loops and so on. The use of such constructs often offers the most intuitive route to the desired SQL solution, especially for those with backgrounds as application developers. Unfortunately, the performance of these solutions is often sub-optimal; sometimes very sub-optimal.
Some of the techniques used to achieve fast SQL code, and avoid row-by-row processing can, at first, seem somewhat obscure. This, in turn, raises questions over the maintainability of the code. However, in fact, there are really only a handful of these techniques that need to be dissected and understood in order to open a path towards fast, efficient SQL code. The intent of this article is to investigate a very common "running total" reporting problem, offer some fairly typical "procedural" SQL solutions, and then present much faster "set-based" solutions and dissect the techniques that they use.
The examples in this article are based on the classic "running total" problem, which formed the basis for Phil Factor’s first SQL Speed Phreak Competition. This challenge is not some far-fetched scenario that you will never encounter in reality, but a common reporting task, similar to a report that your boss may ask you to produce at any time.
In my experience, I’ve mostly found that the ease of producing the solution is inversely proportional to its performance and scalability. In other words, there is an easy solution and a fast solution, as well as many solutions in between. One may argue that for a report that runs once a month, clarity and maintainability are as important as speed, and there is some truth is this. However, bear in mind that while you can get away with a simple solution on a table with a few thousand rows, it won’t scale. As the number of rows grows so the performance will degrade, sometimes exponentially.
Furthermore, if you don’t know what’s possible in terms of performance, then you have no basis to judge the effectiveness of your solution. Once you’ve found the fastest solution possible then, if necessary, you can "back out" to a solution that is somewhat slower but more maintainable, in full knowledge of the size of the compromise you’ve made.
Read more

Posted in Performance, SQL Server | Tagged: Writing Efficient SQL: Set-Based Speed Phreakery | Leave a Comment »
Posted by Ramani Sandeep on February 4, 2010
In this tutorial we will be going over how to create a base page class to handle your sessions. The number one question I get asked time and time again is how to manage sessions, and how to detect if a session has expired. Back in the days before .Net things were a little more complicated when it came to solving this riddle, but with the advent of the .Net Framework 2.0 a new class was introduced, the HttpSessionState Class, which is a member of the System.Web.SessionState Namespace. The new HttpSessionState Class gives us access to session state items and other lifetime management methods.
One of the items in the HttpSessionState class we will be looking at is the IsNewSession Property. This property lets us know whether the current session was created wtih the current request, or if it was an existing session. This is invaluable as we can use it to determine if the users session had expired or timed out. The IsNewSession Property is more robust and advanced then simply checking if the session is null because it takes into account a session timeout as well.
Read more
Posted in ASP.NET, C# 2.0 | Tagged: Detecting ASP.NET Session Timeouts, Detecting Session Timeout and Redirect to HomePage, If Session Timeout Redirect | Leave a Comment »
Posted by Ramani Sandeep on February 3, 2010
How VS debugger could be crashed with IE8?
If you opened multiple instances of IE8 and you attempt to debug your project, you mostly will have the issue where VS debugger just stops and ignores your break points!
Read more
Posted in Visual Studio | Tagged: visual studio debug problem, visual studio debug problem with ie8, vs debug problem with ie8 | Leave a Comment »
Posted by Ramani Sandeep on February 1, 2010
This short article demonstrates how to create a watermark effect on your TextBox and display instructions to users, without taking up screen space.
Note that for demonstration purposes, I have included jQuery code in the same page. Ideally, these resources should be created in separate folders for maintainability. \
Read more

23.052108
72.533442
Posted in JQuery | Tagged: Create an ASP.NET TextBox Watermark Effect using jQuery, TextBox Watermark | Leave a Comment »
Posted by Ramani Sandeep on February 1, 2010
A frequent requirement for ASP.NET developers is to schedule tasks at regular intervals. This can include site maintenance tasks, like cleaning up old files, emailing newsletters on a schedule etc. This article examines one easy option for managing tasks like these without having to configure external tools, and discusses a couple of alternatives.
Read more
Simulate a Windows Service using ASP.NET to run scheduled jobs By Omar Al Zabir
How to run scheduled jobs from ASP.NET without requiring a Windows Service to be installed on the server? Very often we need to run some maintenance tasks or scheduled tasks like sending reminder emails to users from our websites. This can only be achieved using a Windows service. ASP.NET being stateless provides no support to run some code continuously or to run code at a scheduled time. As a result, we have to make our own Windows Services in order to run scheduled jobs or cron jobs. But in a shared hosted environment, we do not always have the luxury to deploy our own Windows service to our hosting provider�s web server. We either have to buy a dedicated server which is very costly, or sacrifice such features in our web solution. However, running a scheduled task is a very handy feature especially for sending reminder emails to users, maintenance reports to administrators, or run cleanup operations etc. So, I will show you a tricky way to run scheduled jobs using pure ASP.NET without requiring any Windows service. This solution runs on any hosting service providing just ASP.NET hosting. As a result, you can have the scheduled job feature in your ASP.NET web projects without buying dedicated servers.
Read more
Hope this helps
Jay Ganesh

23.052108
72.533442
Posted in ASP.NET, ASP.NET 3.5, ASP.NET 4.0 | Tagged: Gloabal.asax, Task Scheduling using Global.asax | Leave a Comment »
Posted by Ramani Sandeep on January 30, 2010
The Exceptional Performance team has identified a number of best practices for making web pages fast. The list includes 34 best practices divided into 7 categories.
1) Content
- Minimize HTTP Requests
- Reduce DNS Lookups
- Avoid Redirects
- Make Ajax Cacheable
- Post-load Components
- Preload Components
- Reduce the Number of DOM Elements
- Split Components Across Domains
- Minimize the Number of iframes
2) Server
- Use a Content Delivery Network
- Add an Expires or a Cache-Control Header
- Gzip Components
- Configure ETags
- Flush the Buffer Early
- Use GET for AJAX Requests
3) CSS
- Put Stylesheets at the Top
- Avoid CSS Expressions
- Choose <link> over @import
- Avoid Filters
4) Javascript
- Put Scripts at the Bottom
- Make JavaScript and CSS External
- Minify JavaScript and CSS
- Remove Duplicate Scripts
- Minimize DOM Access
- Develop Smart Event Handlers
5) Cookie
- Reduce Cookie Size
- Use Cookie-free Domains for Components
6) Images
- Optimize Images
- Optimize CSS Sprites
- Don’t Scale Images in HTML
- Make favicon.ico Small and Cacheable
7) Mobile
- Keep Components under 25K
- Pack Components into a Multipart Document
Read more
Posted in ASP.NET, ASP.NET 3.5, ASP.NET 4.0, ASP.NET Ajax, Css, JavaScript, Performance | Tagged: Best Practices for Speeding Up Your Web Site, Performance | Leave a Comment »
Posted by Ramani Sandeep on January 29, 2010
In this article, I will show you a different way of doing a multi-select in an ASP.NET page. I will keep this article short and sweet so you can just use the code in your applications.
We are going to put our CheckBoxList ASP.NET control inside an HTML div object. I have also added code to support changing the background color of the selected row.
Read more

23.052108
72.533442
Posted in ASP.NET, JavaScript | Tagged: DropdownList, MultiSelect Dropdown in ASP.NET, MultiSelect DropdownList | Leave a Comment »
Posted by Ramani Sandeep on January 28, 2010
These concepts can be applied to any Application which is a good candidate for a SaaS application.
Contents:
- SaaS- Introduction
- SaaS -Challenges
- SaaS -Solution to challenges
SaaS- Introduction
A SaaS application can be defines as any “Software deployed as a service and accessed using internet technologies”. In order to realize a SaaS solution (in fact any solution) we need to do two things:
1) Build our application which can be used as a service over internet by different clients. This could range from a programmatic service (accessed programmatically by other softwares) to a stand-alone application used by different clients. This step is involves us to follow certain steps that are different than developing a normal “On-Premise” or simply called a non-SaaS application.
Typically when we develop an application (a non-SaaS application) then we do assume two things:
-
Application will be installed at client side (e.g., a desktop application) be it through a CD or downloading via internet. This also implies that the client will have to do the maintenance (like upgrading to new version, apply patches, maintain databases etc.) of application even after he has bought the application (not true for Application Service Provider model). This fact is not true in terms of a web application. So we can say that any web application forms a different category of application since it is not installed at client side. But still we cannot call ANY web application a SaaS application.
-
Application will be served to requirement of a particular client. If another client needs some changes in the application, we will make changes in the application source code and then run another instance of that application for the new client. So in nutshell, we assume that one application is meant for one client only. This assumption is true even for a web application.
Here comes the difference! The core of a SaaS application is based on the opposites of these two (above mentioned) assumptions. The following are assumptions that are true for a SaaS application.
-
Application will be typically deployed and maintained by a hosting provider. So, clients don’t have to invest in terms of buying hardware resources and employing the IT staff to manage the application. This will be done by the hosting provider.
-
Application will be accessed by clients using internet. In special cases where a SaaS application is hosted inside the enterprise itself this is not true but still the clients accessing the hosted application will still use internet technologies to access the application.
-
A single SaaS application (in fact a single database too) serves more than one client having different needs. So the application will be designed in such a way that only a single application instance will be able to provide different functionalities to different clients. This model is more popularly known as Multi-tenant model.
Among these assumptions, the last assumption related to multi-tenancy requires a SaaS application to be architected in a special way keeping in mind about certain aspects of a multi-tenant application. These aspects form the challenges of building a SaaS application and also our next topic of discussion.
2) SaaS world does not end just by building the application that satisfies SaaS characteristics. Deploying a SaaS application forms another set of challenges. Typically a SaaS application is deployed by a SaaS hosting provider and the hosting provider is responsible of maintaining the application. So, not only clients get rid of maintaining the application but also ISVs get rid of that aspect.
Microsoft provides end to end resources in developing and deploying a SaaS application. It provides resources ranging from development frameworks and technical resources used to build and design the application to hosting options that assist in deploying the application.
Read more

23.052108
72.533442
Posted in Enterprice Applications | Tagged: Saas, Software as a Service | 2 Comments »