Archive for June, 2007

      Recently I have to use color picker control in my project so that each user has its own UI. The best color picker example I found on blogger.com. This inspired me to create my own color picker control. 

Fig (1) Color picker control.

   Color picker allows user to do following thisng. User controls expose the property to show or hide font selction and See Effect Below section. Below image shows only color picker while Font Selection and See Effect Below Setion are hide.

 Fig (2) Only color picker, Font Selection and Show Effect section are hide.

    User can set the property to display only Font Selection section or Show Effect section or both with color picker control.

    User control also expose two server side properties “SelectedColor” and “SelectedFont” that allows aspx page to get selected color and font server side.

     User control also expose two javascript variables that expose selected color and font through javascript. The name of the variables are UserControl’s ClientID + “_SlectedFont” and UserControl’s ClientID + “_SlectedColor”.  Below is the code snipesst that shows how to accecc these variables.

<uc1:ucColorPicker ID=”UcColorPicker1” ShowEffectSection=”false” ShowFontSelection=”false” runat=”server” />

Fig (3) User control on aspx page

<script language=”javascript” type=”text/javascript“>
        // User controls register javascript variables
       // User Control Name + “_SelectedColor” and 
      // User Control Name + “_SelectedFont”
      function ShowSelectedColorValue()
    function ShowSelectedFontValue()

Fig (4) Script shows how to get selected color and font from java script

   As shown in Fig (3) and (4) user can access javascript variable that represents selected color and font.

   You can use this in your application to allow user to change his own colors and fonts for UI. Once user has selected color and font you can change these in your CSS file. So this change will immediatle reflects in your application. To achieve this you must have separte CSS for each user.

    Here is Color Picker Source Code. Please change the extetion of downloaded file to “zip” and extract it. Create new website in VS 2005 amd click on add existing item from solution. Add both color picker user control and color picker demo aspx page. Set this page as start up page and runt the application.

Happy Programming !!


Read Full Post »

        Hi, in my previous atrlicle I show how to create virtual directory. Here I have attched the code for creating , deleteing or listing virtual directories or website in IIS using ASP.NET and C#.

    Code uses DirectoryService name space which allows access to Internet Information Services (IIS). The System.DirectoryServices namespace also provides access to the Active Directory. The classes in this namespace can be used with any of the Active Directory service providers including Internet Information Services (IIS), the Lightweight Directory Access Protocol (LDAP), the Novell Directory Services in NetWare (NDS), and WinNT.

   Following softeares are required for this project to run successfully.

   * IIS 5.1 or later version
   * Dotnet SDK 2.0
   * Admin access to server on which IIS in installed

       You can download the Source Code  here. Once you download the file pls change the extension from “doc” to “zip”.     Sorry for uploading the code this way. I do not found any option to upload zip file. 🙂

Happy Programming !!

Read Full Post »

      In my recent project, I found a starnge behaviour of PNG file. We have created PNG files with transparent back ground for logo. Everything is working fine in IE 7 , Opera, Firefox and even in Safari. However when we saw the image in IE 6 we found a problem that it does not display as transparent back ground.

    Here is the PNG file with transparent back ground. Just save it to your PC and than open it in IE. If you have IE 6 than you can see light blue back ground and if you have IE 7 it will be transparent.

    Below is the html page that display png image.

<title>PNG in IE: JS Inc File </title>

<!– Add below 3 lines in Head section as shown here. –>

<!–[if lt IE 7]>
<script defer type=”text/javascript” src=”pngfix.js”></script>

<div class=”content“>
<h1>PNG in Windows IE: Inc File Demo </h1>
<p>IE now renders this PNG image properly. View the source to see how
to use the JS Include file method.</p>
<img src=”AboutUSIcon.png” alt=”a PNG logo” />

Fig (1) HTML page that shows PNG file.


   Below is the javascript for “pngfix.js” file.Copy the above JS in new file and name it “pngfix.js”. 

var arVersion = navigator.appVersion.split(“MSIE”)
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters))
     for(var i=0; i<document.images.length; i++)
             var img = document.images[i]
             var imgName = img.src.toUpperCase()
             if (imgName.substring(imgName.length-3, imgName.length) == “PNG”)
                    var imgID = (img.id) ? “id=’” + img.id + “‘ ” : “”
                    var imgClass = (img.className) ? “class=‘” + img.className + “‘ ” : “”
                    var imgTitle = (img.title) ? “title=‘” + img.title + “‘ ” : “title=‘”
                                                  + img.alt + “‘ “
                    var imgStyle = “display:inline-block;” + img.style.cssText
                    if (img.align == “left“) imgStyle = “float:left;” + imgStyle
                    if (img.align == “right“) imgStyle = “float:right;” + imgStyle
                    if (img.parentElement.href) imgStyle = “cursor:hand;” + imgStyle
                    var strNewHTML = “<span ” + imgID + imgClass + imgTitle
                                   + ” style=\“” + “width:” + img.width + “px; height:” + 
                                    img.height + “px;” + imgStyle + “” + 
                                   + “(src=\‘” + img.src + “\’, sizingMethod=’scale’);\“></span>”
                    img.outerHTML = strNewHTML
                   i = i-1

Fig (2) Content of “pngfix.js”” file

Happy Programming !! 

Read Full Post »

         Recently I found a really good article on moving options up and down in list box using javascript. Here is the link.

Happy Programming !!

Read Full Post »

           Recent ly I found a really good article on moving value from one list box to another list box using javascript. Here is the link.

Happy Programming !!

Read Full Post »

Shadow Copying

                A fantastic feature of ASP.NET is that the code for a Web site can be changed on the fly without shutting down the Web server. When a Web site’s file is changed on the hard disk, ASP.NET detects this, unloads the AppDomain that contains the old version of the files (when the last currently running request finishes), and then creates a new AppDomain, loading into it the new versions of the files. To make this happen, ASP.NET uses an AppDomain feature called
shadow copying.

Shadow Copying Assemblies 

            Shadow copying allows assemblies that are used in an application domain to be updated without unloading the application domain. This is particularly useful for applications that must be available continuously, such as ASP.NET sites.

             The common language runtime locks an assembly file when the assembly is loaded, so the file cannot be updated until the assembly is unloaded. The only way to unload an assembly from an application domain is by unloading the application domain, so under normal circumstances, an assembly cannot be updated on disk until all the application domains that are using it have been unloaded.

              When an application domain is configured to shadow copy files, assemblies from the application path are copied to another location and loaded from that location. The copy is locked, but the original assembly file is unlocked and can be updated.

              The following list describes how to use the properties of the AppDomainSetup class to configure an application domain for shadow copying.

  • Enable shadow copying by setting the ShadowCopyFiles property to the string value "true".

    By default, this causes all assemblies in the application path to be copied to a download cache before they are loaded. This is the same cache maintained by the common language runtime to store files downloaded from other computers, and the common language runtime automatically deletes the files when they are no longer needed.

A little example

                 Let’s come to the point. How to enable this kind of stuff in your own application? A really simple and short example:

                 First, write a method to create a new app domain to host the new version of the assembly. As you might know, it’s impossible to unload an assembly once loaded in an appdomain, you can only unload the associated appdomain entirely. What the following method does is pretty straightforward: it tells the CLR (assembly loader) where to look for files and then tells it to enable shadow copying by setting the (wrong-typed; a boolean property would have been much better) ShadowCopyFiles property to the string “true”. Next, an appdomain is created with a unique name using some counter, and the assembly with the functionality is loaded (notice the _ indicates private members of the current class). This method is called when the app starts.

private void LoadAppDomain()
     AppDomainSetup setup = new AppDomainSetup();
      setup.ApplicationBase = “c:\\temp”;
      setup.ShadowCopyFiles = “true”;
     AppDomain domain = AppDomain.CreateDomain(“ShadowCopy domain ” +  
                                                                _domainNumber, null, setup);
      _currentAssembly = domain.Load(“Server”, null);


Read Full Post »

        I have seen lots of questions in diffrent forums for adding items in drop down list or list box using javascript. Below is the script for the same. 


<script type="text/javascript">
    function AddItem(Text,Value)
        // Create an Option object

        var opt = document.createElement("option");

// Add an Option object to Drop Down/List Box document.getElementById("DropDownList").options.add(opt);
        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;
<script />

     You can use this function in for loop to add more than one item.

Happy Programming !!

Read Full Post »

Older Posts »