Get connection string from the web.config

Pass the method and it will return the connection string for that name (works well if you have multiple connections in the config file) and it will retrieve that specific connection string.

If you fail to provide the name of a connection string it will default to your default (usually 1st in the list) to the default string.

#region GetConnectionstring
/// method to retrieve connection stringed in the web.config file

///Name of the connection /// Need a reference to the System.Configuration Namespace
public string GetConnectionString(string str)
//variable to hold our return value
string conn = string.Empty;
//check if a value was provided
if (!string.IsNullOrEmpty(str))
//name provided so search for that connection
conn = ConfigurationManager.ConnectionStrings[str].ConnectionString;
//name not provided, get the ‘default’ connection
conn = ConfigurationManager.ConnectionStrings[“YourConnName”].ConnectionString;
//return the value
return conn;

XSLT transform in asp with Microsoft.XMLDOM

I recently had to transform an xml file into a scorm manifest file. I wanted it to be in UTF-8, but Microsoft.XMLDOM‘s transform method disregards the encoding setting in xsl:output. The transformNodeToObject method doesn’t. I also found out I had to use the save method on the output object instead of writing a file based on the xml property. You’ll find the function I ended up writing to assist me below:

<script language="javascript" runat="server">
function transformXmlFile(xmlfile, xslfile, outputfile){
    var xml = new ActiveXObject("Microsoft.XMLDOM");
    var xsl = new ActiveXObject("Microsoft.XMLDOM");
    var out = new ActiveXObject("Microsoft.XMLDOM");
    xml.async = false;
    xsl.async = false;
    out.async = false;
    xml.transformNodeToObject(xsl, out);;
    xml = null;
    xsl = null;
    out = null;

IE8 aggressive caching fix

Apparently Internet Explorer 8 has a more aggressive caching mechanism than any other browser I’ve ever met. To fix it I’ve added the following to almost every dynamic page on my server.

// prevent caching (asp classic jscript)
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;
' prevent caching (asp classic vbscript) '
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
// prevent caching (php)
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: ' . gmdate(DATE_RFC1123, time()-1));
// prevent caching (C#)
//Response.AddHeader("Cache-Control", "no-cache");
//Response.AddHeader("Pragma", "no-cache");
//Response.Expires = -1;


Remember to set UpdatePanel’s UpdateMode to Conditional

Since the cool thing about the ASP.NET Ajax UpdatePanel is that its contents are updated asynchronously when an event that would normally generate a postback is raised inside, one would think that this is its default behavior.

But it’s not: the UpdateMode property of the UpdatePanel has 2 possible values:

  • Always
  • Conditional

and the default value is Always.

When set to Always, the UpdatePanel is updated on every postback raised from anywhere in the page, so from controls inside the panel, inside other panels or just on the page.

When set to Conditional, the UpdatePanel will be updated only on postback originated by controls inside the panel or from the triggers specified.

So, if you have multiple update panels and you don’t want to update all of them to be updated every time, you have to set the UpdateMode to Conditional:

<asp:UpdatePanel ID="UpdatePanel1" 

I spent all the day trying to understand why it took so long to refresh a small area with only a few labels, and it was because I didn’t set the UpdateMode to Conditional.

I don’t understand why the default is Always and not Conditional, but not that I know, it’s not a big deal: just have to remember to always set the UpdateMode.

Windows Azure Training Session at LMKR

Windows Azure™ is a cloud services operating system that serves as the development, service hosting and service management environment for the Windows Azure platform. Windows Azure provides developers with on-demand compute and storage to host, scale, and manage web applications on the internet through Microsoft® datacenters.

Windows Azure is a flexible platform that supports multiple languages and integrates with your existing on-premises environment. To build applications and services on Windows Azure, developers can use their existing Microsoft Visual Studio® expertise. In addition, Windows Azure supports popular standards, protocols and languages including SOAP, REST, XML, Java, PHP and Ruby. Windows Azure is now commercially available in 40 countries.

I was recently called by Microsoft Innovation center to speak at LMKR (LandMark Resources), an international software company involved in developing and implementing solutions for storage, processing, simulation and integration of sub-surface data. Held on 8th April 2011.

It was an interesting session for me and the audience I believe. I have seen much interest in the rising hosting technology that was a positive sign. I thoroughly enjoyed it.

LMKR Training Session

LMKR Training Session

Coding night at TEO

TEO is a wonderful organization, always working on its motto that is “Passion for Software Development”. Passion is not something that is developed, it is inborn. Like some matchsticks in a matchbox, unless someone put the matchstick in hand and strike it against the matchbox, it is not ignited. Same case we need some source to ignite our passion. Fortunately our offshore team was also here, so we decided to have an event where we take a problem, all of us sit together, design it, develop it and host it.
We got a good support from Microsoft Innovation Center, Pakistan. I thank Mr. Jibran Jamshaid for being so kind to send goodies for the event.
So first part, i designed a passion ignitor poster. Here it was;
Coding night at TEO

Coding night at TEO

The event started at 7 PM. We gathered in the war room, discussed the problem on the whole. It was like the whole team was united, with different backgrounds. We had PM’s, architects, developers, Senior SE’s. This was fun. A real thing we would be achieving through this marathon was Team building. And i believe if we achieve just this, we would have achieved a lot. Out mission was to develop a full fledge media server, develop it in .net technology, and host it over Windows Azure.
We divided the guys into five teams. And the coding night begins. Let me share few pictures of the event here, which will give you an idea of intensity we had there.
Coding Night Analysis Session in Progress

Coding Night Analysis Session in Progress

Ideas floated like tsunami

Ideas floated like tsunami



Developers at fuel station

Developers at fuel station

Fifteen of the very best of TEO  got together at the first “Coding Night”.
The night started at 7:00 PM (yes we were fashionably late) with a discussion on the requirements. Where we discussed the problem at
hand, every one pitched in with their ideas. A candidate solution was decided in this meeting in 90 minutes. 4 Teams were made to work on the four different modules of the solution.
The teams went back to the keyboard further refined their tasks and coded to complete their respected modules. During this time they
communicated with each other about the integration points.
Finally everyone was done around 11:45 and we started the integration by putting the code on the big screen. Few tweaks here are there and we were home.
It was a great experience at the very least. We took a problem discussed it, designed it and solved it, all in the course of 5.5 hours.
I am very happy to say that we do have a working demo for the solution built in the coding night which is hosted
on the Microsoft Windows Azure. This demo will be soon shared with all of you.

I would like to thank everyone who participated in this Night and I hope that this tradition will carry on in TEO.
In the image you will see the names of the people who participated in the event.

Coding night at a glance

Coding night at a glance