Adnan’s Blog

New Blog!

Posted by: adnanrashid on: September 21, 2009

Hi everyone!

I recently decided to move my blog to a private host. I have updated various aspects of the new blog which is available at http://www.adnan-rashid.com/

See you there…

jQuery Tools

Posted by: adnanrashid on: August 26, 2009

I recently came across a very nice jQuery control library called jQuery Tools. The library features the following JavaScript tools :

  1. Tabs
  2. Tooltips
  3. Expose
  4. Overlay
  5. Scrollable
  6. FlashEmbed

So now you are thinking “Whats so great about this? We already have tons of jQuery plugins for this…”. I thought so too.

The striking advantage of this library is that these tools can be combined, extended and styled, giving you potentially unlimited options for creating customized widgets for your web pages. The website also features great and detailed examples to help you get started, and features some of the best practices recommended by Yahoo engineers. [ref : Best Practices for speeding up your website]

Organize Usings

Posted by: adnanrashid on: August 23, 2009

During your development, you may notice that your code file contains using directives which are not required by your code. The Visual Studio IDE provides the Organize Usings option to remove/sort these using directives. To access this option, right-click anywhere within your code editor and select one of the sub-menu options for Organize Usings option.

  1. Remove Unused Usings : This option will remove any using directive not required by your code. Note : Please build your application before executing this option to ensure that any required directives are not removed.
  2. Sort Usings : This option will organize your Using directives alphabetically giving precedence to the System name-space.
  3. Remove and Sort : Use this option to execute the above operations together.

Organize Usings

Javascript Formatting

Posted by: adnanrashid on: July 15, 2009

Like most developer I love jQuery and appreciate the intellisense support in Visual Studio. I am very particular about the format for my code and often use the Document Format option of the IDE. What I noticed was that my braces were never placed on new lines, and I wanted to change this. So here’s what you can do :

  1. In the Tools menu, select Options…
  2. Check the Show all settings options
  3. In the Text Editor > JScript choose the Formatting option.
  4. On the right pane, there are two options under the ‘New lines’ section. Check them as per your requirement.

Javascript Formatting

Javascript – Query String Parameters

Posted by: adnanrashid on: March 4, 2009

Here’s a small javascript helper to read Url Query String Parameters.
 

function GetUrlParams()
{
          var vars = [], hash;
           var hashes = window.location.href.slice(window.location.href.indexOf(‘?’) + 1).split(‘&’);
 

        for(var i = 0; i < hashes.length; i++)
        {
                hash = hashes[i].split(‘=’);
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
        }
        return vars;
}

The above function, will read the url, get the query string part i.e from (“?”) and split each paramter by the (“=”) character and create a name value pair allowing us to access the param value using the param name.

 

For example, if we are have a test.htm in http://www.example.com and the url is : http://www.example.com/test.htm?fname=Adnan&lname=Rashid

To access the param values we can use something like :

var params = GetUrlParams();

alert(params["fname"]);

alert(params["lname"]);

Multiline TextBox Length Validation

Posted by: adnanrashid on: January 10, 2009

Unlike the normal TextBox, the MaxLength property doesnt work for MultiLine TextBox. Heres a small trick to solve the problem:


<asp:TextBox ID="txtExample" runat="server" TextMode="MultiLine" />
<asp:RegularExpressionValidator ID="revExample" runat="server"
ControlToValidate="txtExample" ValidationExpression="[\s\S]{1,200}"
Display="Dynamic" ErrorMessage="Length cannot be greater than 200 characters" />

The above markup validates the revExample TextBox / textarea and limits the max characters to 200. By modifying the regular expressions, we can validate fields for any scenario. If you are looking for some Regular Expressions to get started out, just point your browser to http://regexlib.com/

Cheers!


Conditional Breakpoints

Posted by: adnanrashid on: December 23, 2008

Visual Studio is filled with nifty tricks, which if leveraged properly in the right situation can make the developers life easy. Consider if you had a looping statement, and wanted to debug it, but only for a particular value. Rather than hitting the breakpoint every time, you can shorten the hits by using a Conditional Breakpoint.

To set a Conditional Breakpoint, right-click the Breakpoint circle and select the Condition option.

Conditional BreakpointYou can then define the condition and additionally select an option to filter the condition for evaluating the condition, or for raising the breakpoint when the value of the expression changes.

“Attach to Process…”

Posted by: adnanrashid on: December 22, 2008

The average programmer uses the general Debug mode by using the “Start Debugging” option from the Debug menu, or the F5 shortcut key. But what if you want to debug an application that is already running? If you faced this problem, then this tip should lighten up your day.

Choose Debug | Attach to Process….

Select the aspnet_wp.exe from the list of Available Processes and click on Attach

Attach To Process...

Attach To Process...

Alternatively you can also use ALT + D , P to select the option.

jQuery Charts

Posted by: adnanrashid on: November 22, 2008

Although there are tons of charting / reporting plugins ranging from inline charts to flash charts, each one is unique in terms of technology, footprint or usage. I needed something compatible with jQuery and supported many as many chart types as possible. Here is the pick list:

1. jQuery Google Charting (http://www.keith-wood.name/gChart.html)

This plugin allows you to leverage the power and simplicity of Google Reporting. Easy to use with detailed examples, and wide support for chart types makes this an impressive must see.

2. Flot (http://code.google.com/p/flot/)

This plugin is very similar to its prototype counterpart Flotr. Again kudos for good examples and an excellent plugin.

3. Canvas Chart Plugin (http://www.filamentgroup.com/lab/creating_accessible_charts_using_canvas_and_jquery/)

Another great plugin, but does have a few rough edges on the cross-browser compatibility due to the issue of canvas tag support in some browsers like IE. Luckily there’s a good plugin to solve this problem, which they have also mentioned on their website.

vCalendar

Posted by: adnanrashid on: November 18, 2008

I needed to integrate support for vCalendar in my current project. So i went through the vCalendar spec 1.0 at http://www.imc.org/pdi/vcal-10.txt and wrote this class. Although I have not implemented all the specification features, but this should prove sufficient for the usual requirements. If you have any comments / suggestions , let me know.

Read the rest of this entry »

Tags: ,