Navigation

Search

Categories

On this page

Removing unused CSS Classes from your web application
Asp.Net Session Timeout control
Fixing Gaps in Corners while using Ajax control toolkit RoundedCorners Extender
I am on Twitter
Cool Silverlight app
Get free Visual Studio 2008 and .NET Framework Training kit
Registration for VS2008, Sql Server 2008 and Windows Server 2008 launch event now open
Debugging Dot Net Source Code in VS2008
Concatenating rows in a table into a single string using sql

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 23
This Year: 0
This Month: 0
This Week: 0
Comments: 7

Sign In

 Wednesday, October 01, 2008
Wednesday, October 01, 2008 7:46:35 PM (Mountain Standard Time, UTC-07:00) ( asp.net | css | utilities )

Most of you might have seen that while working on a Website project, the CSS gets harder to maintain as the site ages. This might be due to new developers coming in to the project, removal of UI elements (but not the corresponding CSS), refactoring and so on. I think it is a good idea to revisit and clean your css every few weeks before it becomes totally unmanageable. In this post, i am going to outline 2 ways to do so
There is a great Firefox plugin called Dust-Me Selectors which can test individual web pages or spider your Website to find unused CSS selectors. As you navigate from page to page in your Website, it maintains a list of unused CSS selectors that you can remove.
If for some reason you cannot use the plugin, or would like to be more sure, I have also created a small utility (for personal use) that can parse a CSS file to create a list of defined classes and go through the code base to determine which of those classes are actually being used. This utility usually gives me a list of unused CSS classes with an accuracy of greater than 95%. It cannot give a 100% accurate output in cases where the css classes are being assigned dynamically in JavaScript or server side code (it catches some of them, but not all). But it gives you a great starting point. I normally search my codebase for the CSS class name before commenting it out from the CSS file to be sure its not being used in the code anywhere. I delete the commented out CSS classes after a couple of releases if I do not see any issues.
You can download the utility (named CssCleaner) from here. Please remember that this does not come with any kind of warranty, I am just sharing this so that it can be helpful to somebody in a situation similar to mine.
CssCleaner is pretty simple to use. Download the app, unzip it to a folder on your system. You should see 2 files - CssCleaner.exe and CssCleaner.exe.config. The config file is needed by the application and is present to make a couple of things configurable. I'll talk more about it in a second.


After you run the application, click on "Choose Application Folder" and choose the code base folder for your Website. Click on "Choose CSS File" and select the CSS file that you want to analyze. Change the File Filter if you would like to process files different from the default types. Leaving that textbox blank processes all files. Click on "Process" to run the utility. The unused classes get loaded on the right hand side. In my use, the tool has been pretty fast.
If anybody is interested in the implementation, i use a parser/scanner to parse the CSS file similar to this. Then I go through all the files in the code base, building a list of  used CSS classes using a regular expression. The regular expression is picked up from the config file, so you can tweak it as you find suitable. The other thing picked up from the config file is the list of default file types to search for. It then compares the used CSS class list against the available CSS classes and displays the unused classes list.
If you have any suggestions for the tool, or find any bugs, please leave a comment or email me (latish.sehgal at gmail dot com) and I'll try my best to implement it. I hope that you find this tool helpful.

 Friday, August 29, 2008
Friday, August 29, 2008 3:32:43 PM (Mountain Standard Time, UTC-07:00) ( )

As web application developers, we depend on the Session to store data pertaining to the user. It's a common scenario that the user might take a half an hour break to take a phone call or a meal while using the application and come back to find out the site behaving in an unexpected manner because his session would have expired (default value for session timeout is 20 minutes). As a developer, it's a good practice to check a session variable for null value before using it, but you can create a much more user friendly environment by redirecting the user to a web page indicating that his session has timed out. The best way to do this is by creating a user control that you can just drop on your master or content page as desired.
I looked around for such solutions, and I have described below 2 such good implementations that should cover most scenarios.
Implementation 1
You can create a web control similar to what Peter Bromberg has outlined here.
This control checks for the HttpSessionState's IsNewSession property and the presence of the ASP.NET_SessionId cookie to determine if the user session has expired. It redirects the user to a timeout page if the session has expired. All you need to do is drop the control on your page and assign the RedirectURL property to your timeout page. The control works for both synchronous and aynchronous postbacks (for those of you using Asp.Net Ajax), and the only downfall for this method is that there's no way to warn the user that his page is about to timeout.
Implementation 2
If you would like to warn the user before his session actually times out, you can create an Asp.net AJAX friendly control similar to what Travis Collin's solution.
This control pops up a warning to the user some time before his session times out and gives him a chance to save his session. You can configure the UI of the warning and the time for warning and timeout while using the control. The only thing to watch out for here is that the developer has to make sure the session (and form) timeout value are in sync with the one configured on the control. I faced a small issue in this implementation because it was not recognizing asynchronous postbacks as user activity. To fix this, all i had to do was add a client side handler for page load and reset the timeout there as well.
    initialize : function() 
    {  
        ....
        Sys.Application.add_load(Function.createDelegate(this, this._handlePageLoaded));
        .....
    },
        _handlePageLoaded: function(sender, e)
    {
        this._resetTimeout();
    },

 Wednesday, August 20, 2008
Wednesday, August 20, 2008 4:59:17 PM (Mountain Standard Time, UTC-07:00) ( ajax | asp.net | extenders | Rounded Corners )

We noticed gaps in the borders for some of our controls while using the RoundedCorners Extender. This was a big headache since it seemed to work fine on some pages. I have included a sample image below.

We finally figured out that on the pages where it was not working, we were injecting some diagnostic information into our html as comments. Since this was being inserted before the doctype, it was sending IE into quirks mode and that was causing the trouble. Updating the code to insert comments after Doctype declaration fixed the issue.

Hope this helps somebody out there:).

-Latish Sehgal

 Tuesday, May 13, 2008
Tuesday, May 13, 2008 8:02:30 PM (Mountain Standard Time, UTC-07:00) ( )

You can follow me here.

 Friday, March 07, 2008
Friday, March 07, 2008 3:37:43 PM (Mountain Standard Time, UTC-07:00) ( Silverlight )

Check out the Silverlight implementation of John Conway's game of Life.

Keep an eye on your browser CPU Usage :).

 Wednesday, February 27, 2008
Wednesday, February 27, 2008 9:59:51 AM (Mountain Standard Time, UTC-07:00) ( .NET 3.5 | VS2008 )

Get it here.

This kit includes presentations, labs and demos.

Now only if I could find time to go through this :(.

 Monday, January 21, 2008
Monday, January 21, 2008 12:08:49 PM (Mountain Standard Time, UTC-07:00) ( MSEvent | VS2008 )
Registration for the "Heroes Happen Here" MSEvent has now begun.
You can find out more here.



Not only do you get to test drive the new products and meet the experts, but you also get free promotional versions of all 3 products. Its happening in Denver on March 20 at the Colorado Convention Center.

This is really cool, looking forward to this one!!! See you there.

-Latish Sehgal

 Wednesday, January 16, 2008
Wednesday, January 16, 2008 4:51:53 PM (Mountain Standard Time, UTC-07:00) ( )
Its here!! You can now debug the dot net source code in VS 2008. Read more about this in Shawn's post.
I am still not sure how beneficial this will be in day to day programming, but i guess it will be helpful in troubleshooting sometimes. Especially when it looks like we have found a bug in the framework :) (For the record, i never found a bug in the framework).
-Latish Sehgal

Wednesday, January 16, 2008 4:22:21 PM (Mountain Standard Time, UTC-07:00) ( oracle | sql )
Today i came across a new scenario in one of my applications (that talks to an oracle database) where we had to concatenate a field from multiple rows in a table into a single string. While some suggested that  string manipulation could be done inside the web application code after retrieving all the data, my alert (read over-caffeinated) brain was sure that there must be a way to tackle this at the database level by manipulating the sql query. 30 minutes with the Google gods proved me correct. I have created a brief test case with the solution below, if you run into a similar situation.
 To create the test table, run CreateTable.sql (.91 KB) after saving it to your system.
 Our table looks like this, and our goal is to create a concatenated string of all the names.


 
The sql uses SYS_CONNECT_BY_PATH() (used for hierarchial queries), and the final sql is

SELECT LTRIM(SYS_CONNECT_BY_PATH(Employee_Name, ','),',') Concatenated_Names
FROM (
      SELECT Employee_Name, ROW_NUMBER() OVER (order by Employee_Name) rownumber, COUNT(*) OVER () cnt
      FROM (SELECT Employee_Name FROM Employee)
) data
WHERE rownumber = cnt
START WITH rownumber = 1
CONNECT BY PRIOR rownumber = rownumber-1;

Below is the result of the query.


-Latish Sehgal