Adnan’s Blog

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: ,

Asp.net Read Reciept Request

Posted by: adnanrashid on: September 28, 2008

Heres a quick tip. If you need to include a request for read receipt like Microsoft Outlook while sending mails through Asp.net, just add the Disposition-Notification-To Header to the MailMessage.

The MailMessage class does not have a corresponding attribute and thus it has to be set through the Header.

MailMessage mm = new MailMessage(fromAddress, toAddress);
mm.Subject = subject;
mm.Headers.Add("Disposition-Notification-To", sendReadReceiptToAddress);

Please keep in mind that this is only a request, and can be rejected/ignored by the Mail Client/User configuration.

Generic Handler – Session State

Posted by: adnanrashid on: September 26, 2008

In my current project I needed to access the Session state in a Generic Handler. To my dismay, i realized that the Session StateBag was null. The StateBag class is sealed and manages the Viewstate of the Asp.net server controls and pages.

Upon discussion with my colleague, Mr. Hamed, we found the solution to my problem. Using the IRequiresSessionState interface in System.Web.SessionState, we got access to Session state.

According to Microsoft “Specifies that the target HTTP handler requires read and write access to session-state values. This is a marker interface and has no methods.

Another option was to use the IReadOnlySessionState interface (Specifies that the target HTTP handler requires only read access to session-state values. This is a marker interface and has no methods.)

Needless to say, there is a performance increase in the latter case and if your requirement is only to read Session state, then that would be the right choice

Remove project from Recent Projects in Visual Studio

Posted by: adnanrashid on: September 15, 2008

Recently, I felt the need for removing a project from the Visual Studio Start Page, so I Googled and would like to share the solution. Don’t forget to close visual studio before trying this out. This trick requires modification to registry, so if you are skeptical do make a backup of the registry before proceeding.

Start the registry :

Start > Run > regedit > HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\ProjectMRUList

Then delete the key that has the project you want to remove.

Visual Studio > 9.0 > ProjectMRUList

Visual Studio > 9.0 > ProjectMRUList

Note:

  • The Project Keys are consecutive. So if you have 5 projects listed, and you delete the key for the 4th project ie File4, the 5th project (File5) will also not be shown. You will need to remain one of the keys so that the list remains consecutive.
  • The same procedure can be repeated for the FileList and Find sections of the registry

Google Chrome

Posted by: adnanrashid on: September 14, 2008

Being a Web Developer, I don’t know whether to rejoice the addition of another browser or not? With all the hype of IE 8 ; Cross-Browser compatibility and now this, life sure is chaotic.

I am not going to blog about the new features of Google Chrome (We already have tons of them). It’s been analyzed that Chrome has been optimized for Google Applications and Services. Is that a bad thing??? Frankly, i don’t think so, cos admit it or not, every netizen is dependent on them. But i do welcome the Process-Thread architecture in Chrome, cos i had the same problem in both IE and Firefox.

We can all expect great things from Google, lets hope its the same with Chrome. Good luck to the development and Congrats on the Beta release.

7 really awesome things about Google Chrome : http://mashable.com/2008/09/03/awesome-google-chrome/

Google Chrome Introduction (Comic Book) : http://www.google.com/googlebooks/chrome/index.html

Tags: