Control ctl00_ContentMain_ xxxxx of type ‘GridView’ must be placed inside a form tag with runat=server

Recently I wrote some simple code to Export the contents of a GridView to Excel. You know, the basic stuff like changing the type to application/ms-excel content and removing Images from the GridView (so that they don’t appear as missing images in the Excel sheet) and converting Hyperlinks to Labels.

The Problem : But when I ran my code, I got the dreaded error :Control ctl00_ContentMain_ xxxxx of type ‘GridView’ must be placed inside a form tag with runat=server

The Solution :  Just place this code in your codebehind. And that will fix ya! :

public override void VerifyRenderingInServerForm(Control control) {}

The Explanation :
Asp.net calls VerifyRenderingInServerForm to ensure that every single server control is being rendered inside a <form runat=”server”> tag. Which makes sense for a web page.  But it doesn’t make sense for an Excel sheet. Since, we just want to send the Gridview contents to the client and not the Form tag.

All we are doing here is overriding this Method and falsely reporting to Asp.Net that our Control is actually being rendered inside a <Form Runat=’server’> tag.

Hope it helps…

Installing Windows 7 (using Bootcamp) on a Mac with Parallels installed on it

I finally managed to install Windows 7 beta on my Macbook. I must say I am liking it so far. Of course it is a beta, so you have to keep that in mind. Plus, I am still hunting for drivers for my sound card(found it..see below for link) and isight camera. The setup for Windows 7 was smooth as a cake. Thats what I call unattended setup. No questions asked! the computer reboots a couple of times you enter the product key, and you are golden :)

The reason why I am writing this blog entry is that I wasted a lot of time getting Boot Camp to partition my Macbook hard drive so that I can install Windows on it. And I finally found a solution for it.

The problem : My Macbook with Leopard on it has a 200GB hard drive and only 5 GB was free. Also, I have a Vista installation on my Macbook which I run using Parallels desktop software. It is much better than Virtual PC.

So, obviously with 5 GB space I couldnt do anything. First I had to use a software called Diskkeeper to tell me which files were eating up all the space. I found a lot of redundant stuff, which I deleted and finally was able to create 50gigs offree space. I was happy with my cleanup. 

I fired up Bootcamp and gave 32GB to the Windows parition that I was about to create. But, after running for 5 minutes, Boot camp comes back with an error saying that some files could not be moved and the paritioning failed ! :(

The Solution: After doing lot of research,  I finally found that the culprit was the Parallels desktop .hdd files.

So, I moved the entire Documents–>Parallels folder to my 32GB usb drive (formatted with Mac OSX partition). To move it you simply drag and drop it while keeping the Command key pressed. This created 30GB more free space on my Mac. And Boot camp had no problem creating the parition after this.

e free space on my Mac. And Boot camp had no problem creating the parition after this.

The bottomline is that Bootcamp doesn’t fail because you have less disk space, it fails because the .hdd files used by Parallels desktop are either marked readonly or are too big for it to move around to create a new partition.

Drivers : I found the driver for the sound card. Here is the direct link to the manufacturer’s site : http://www.realtek.com.tw/downloads/downloadsView.aspx?Langid=1&PNid=14&PFid=24&Level=4&Conn=3&DownTypeID=3&GetDown=false

Phone buddy for HTC Touch diamond and Touch PRO released !!!

UPDATES :

  • [3/3/2009] Added a new option which allows you to enable tilt even in darkness. I had deliberately disabled it for valid reasons, but some people thought the tilt feature suddenly stops working not realizing that it is intentionally disabled in darkness (i.e in your pocket)
  • [2/9/2009] Two major improvements. Added very precise calculation for the Tilting feature. Also, the Shake feature is extremely sensitive and reliable(try with Sensitivity 15)
  • [1/27/2009] The fully functional 5 day trial version is available for download here. Please uninstall Meeting Buddy from your phone first if you have it installed.
  • Microsoft.NET 3.5 framework can be downloaded here. Copy this cab to your phone and run it from the phone.
  • If you like the trial version it is also available for purchase : (I prefer the Paypal method because Pocketgear pockets more than 50% of the sales proceeds from me)
  • PAYPAL : (Preferred) – $5 only !!
    btn_buynowcc_lg
  • POCKETGEAR :$6
    pocketgear

Phone Buddy is an upgrade to Meeting Buddy for HTC Diamond. It has many more features than Meeting Buddy and the price is the same. I have highlighted all the new features in Red

  • Tilt Control: The biggest featuer that I have added to Phone Buddy compared to Meeting Buddy is Tilt Control. When enabled it will go forward/backward depending on the screen you are on when you tilt your phone left or right. See video below
  • Flip phone to vibrate : Puts your phone into vibrate mode when you put your HTC Diamond face down, and will set it back to normal ringer when you put it face-up. It uses HTC Diamond’s built in accelerometer/G-Sensor for this.
  • If you check ‘Use Outlook Integration’, Phone buddy will put your phone into vibrate mode only if it sees that you are in a meeting (It does this by checking your phone’s outlook calendar)
  • If you use ‘Outlook Integration’ another settings becomes available to you called ‘Pocket Sensor’, if you check this, Phone Buddy will put your phone into vibrate mode, if it senses darkness (i.e your phone is probably in your pocket). It uses HTC Diamond’s light sensor for this.
  • Phone Buddy also has an option which allows you to lock/unlock the phone automatically using ambient light. So, if it is dark it will lock the phone’s keyboard. (So you don’t accidentally dial someone when your phone is in your pocket). It will unlock the keyboard as soon as you take it out of your pocket. You can also tell Phone buddy to activate this feature between certain hours of the day. eg. between 7 Am and 5 Pm.
  • Another option that it gives you is to lock/unlock the phone when you shake your phone. I have added the option to control Shake sensitivity too.
  • ‘Auto unlock on Incoming call’ is very obvious. If your phone’s keyboard is locked and Phone Buddy detects an incoming call, it will unlock the keyboard or you, so you don’t have to fumble around.
  • Auto unlock when Stylus removed’ unlocks your phone as soon as you take out the Stylus.
  • Hassle Free Installation’ No need to copy a .CAB file to your phone and run it. You can simply run the setup on your desktop and it will automatically install it to your phone.

Here are screenshots of the Configuration options for Phone Buddy :

  • fliptovibrateautolock
  • tiltcontrolfeedback

The good news is that it will be available for the same price, and all existing buyers will get a free upgrade. I will continue to offer Meeting Buddy for download as well (Although I don’t know why people would want that)

If you like the software buy it here :

PAYPAL :
btn_buynowcc_lg

POCKETGEAR :
pocketgear

Check out these other Titles too :

Get rid of Regsvr32, Regasm, Gacutil… A Shellextension for .Net and COM dlls

I had originally written a Shellextension for COM dlls, which would give you the option of registering/unregistering a dll (if it is a com dll) by right clicking on it. Here is the original post :http://nishantpant.wordpress.com/wp-admin/post.php?action=edit&post=11

After several years, I finally took out some time and created a Shellextension which works for .Net assemblies as well. These are the few features it has :

1. If you right click on a DLL and if it is a COM Plus dll it will show you the following menu.

COM Plus DllsIf you click on a COM dll but it is not installed in COM+, then you will get all above options except, the last 3 options which are relevant to COM+ only. Also, if you right clik a COM only dll, then it WILL give you an option called “Create COM+ package”.

2. IF you Right click on a dll which is a .Net assembly and is Strong Named as well, you will see the following menu :

If you right click on an Assembly which is not Strong Named, you will see all options except GACUTIL

3. If you hover your mouse over a dll which is a .Net dll, you will see some brief information about the dll like below :

4. If you right click on an Assembly, you will see a menu option called “Open with Lutz Reflector”. In case you dont know what Lutz Reflector is, it is an awesome free tool written by Lutz Roeder which disassembles any .Net assembly and shows you the source code in a very easy to view typelibrary browser. Since you could have downloaded Lutz Reflector anywhere in your PC, my shellextension will prompt you for the location just once when you first click on this option. It will then remember the location and will just open the Reflector with your assembly loaded in it.

Tested with Lutz Reflector 5.1

UPDATE (8/21/08) - Just heard from Lutz Roeder, that his software will be further developed and maintained by Red-Gate software from now on. (It will still be free though). See link for details –>Click to see article

5. If you go to the thumbnail view of any folder which has dlls, the shellextension analyzes the dlls and puts and changes their icon which helps you identify them. The Shellextension can distinguish between a regular dll, COM dll, .Net 1.0, 1.0, 2.0, 3.0 and 3.5 assembly. See below :

6. Last but not the least, you can customize the behavior of the dll and turn the ShellExtensions off or on. You can toggle, IconHandler extension, Right Click context menu extension and ToolTip extension. Here is a snapshot of the configuration screen :

This is the first time I am releasing this ShellExtension, so there may be a few bugs in it. I would really appreciate if you can report the bugs to me by leave a comment in this post. I will try to work on them as soon as I can find time.

DOWNLOAD/Setup :

Create pdf documents for free

Here is an open source printer driver. Once you install it on your machine it will create a fake printer on your computer. Printing any document to this printer, will cause your document to be converted into a .PDF file. Pretty neat!

  • Close programs like Outlook, Word, SQLEdit, Visual Studio etc. (otherwise the setup may fail)
  • Install the software (accept all defaults), it will create a new printer on your machine called “PDFCreator”.
  • To create pdf documents all you need to do is to print to this printer. It will prompt you for the PDF location and will automatically open the PDF after it is created.

An enhanced UpdateProgress control, which shows an animation at the point where mouse was clicked

Also Check Out: My latest venture. http://loqly.me – a way for you to ask questions and get answers about local businesses around you. iTunes link:http://bit.ly/e5u4jv (only available in US for now)

WHY DO IT ???

Before you read the post, let us answer why did I waste time in changing the behavior of the UpdateProgress control. Here is the deal. Suppose, you have 5 or 6 controls on your page, which when clicked result in an Ajax call. You know that the UpdateProgress control is pretty much static, meaning, wherever you put the <asp:UpdateProgress> tags, that is the place where the progressbar will show up when your Ajax call is in progress. So, no matter which control the user clicks the progressbar is being shown in a fixed place. Why may some people consider this bad ???

  • You or anyone looking at the screen, may lose track of why you are waiting because the progressbar just shows that you are waiting not what has triggered the wait.
  • If the page is long, and the progress bar is at a fixed place, there is a possibility that you clicked a control which is a scroll length away from where the progressbar will show.
  • If the control which was clicked can give a feedback for the user to wait, it prevents the user from clicking the same button twice.

So, much for justifying why I wrote this control. But those were just a few thoughts behind it. Let us get back to the nitty gritties. Btw, here is a YouTube vide of how it looks (video is a little fuzzy but it shows what I am trying to communicate)

The Code :

I will not go into too much detail explaining the code, because I am sharing the source code with you. But here is the high level overview :

  • Create a new control, which inherits from UpdateProgress control
  • Embed two resources in your control assembly. (the default hourglass image and the javascript used to make this control work)
  • Override Render method, and inject javascript. The javascript will hook into the AJAX InitializeRequest and EndRequest events, by calling add_initializeRequest() and add_endRequest() methods of Sys.WebForms.PageRequestManager class.
  • The first Image control in the <ProgressTemplate> of the UpdateProgress control will be assumed to be the hourglass image, and if you haven’t set an ImageURL value for it, a default image will be supplied. You can create your own hourglass images from this awesome website : http://www.ajaxload.info/#preview

That is it. Do leave comments and suggestions if you find this control useful. I am also attaching the source code and the assembly. If you don’t want to see the code, just use the assembly and things should work right away.

Migrating Sourcesafe database from one server to another in 5 steps

UPDATE: The easiest way to move a VSS database to a new server is to copy the whole database in one shot. If your database is small this works like a charm. See this MS KB article for details. The only gotchas are :

  1. This involves copying the complete VSS folder over the network. This may be slooooow and the file copy may even fail suddenly for no reason.
  2. If the VSS db is real big then even winzip will stop at 65K files, so rule out that option if the no of files > 65K. Even winrar doesn’t work. I haven’t tried Lharc or ARJ yet.

    —————————————————————————————-

    Original Post

    If you have found this article, it means you haven’t had much luck trying to find how to migrate VSS from one machine to another. Also, many of you must have noticed that MS KB article http://support.microsoft.com/kb/q176875/ is bogus and the syntax for ssarc does not work. So, how do you actually move your VSS sourcesafe database ????

    STEP 1: Use SSARC.EXE to archive your existing database.
    Here is the syntax which I got working for me after umpteen trial/errors :
    ssarc “-s\\vssserver\vssfolder” d:\Archive.SSA $

    1. Notice that -s is inside the quotes
    2. $ means the whole VSS should be archived starting from root. You can specify sub branches too. eg. $/Projects or $/Project/Project1
    3. Make sure you enter ‘N’ (NO) when ssarc asks you if you want to delete the existing database after it has been archived.

    STEP 2: Run SSRESTOR.EXE to restore the database on the new server.
    ssrestor “-s\\NewServer\VSS” d:\ArchivedProjects.ssa “$/PathYouWantToRestoreTo”

    STEP 3: Copy existing users from your current VSS installation.
    Copy VSS\Users folder, VSS\Users.txt file and Um.dat file to the new installation

    STEP 4: Run Analyze -F “C:\Program Files\Microsoft Visual Studio\VSS\Data. This will re-generate the rights for all the users based on um.dat. Remember you just cannot simply copy rights.dat file to do this.

    STEP 5: You can either change the current srcsafe.ini to point to the new database, so that developers don’t get a broken link. Or you can just shutdown the server and tell people to reload their projects from the new server.

    Thats it. When you complete step 5….your VSS migration is complete !!!!

    Further Reading:—————

    Problems/Fixes for integrating VSS with Interdev:
    http://www.codeproject.com/asp/VSS_and_VID.asp?df=100&forumid=136229&select=1313406&msg=1313406

    User right setup for VSS:
    http://support.microsoft.com/kb/131022/EN-US/

    Use of http://codebetter.com/blogs/darrell.norton/archive/2004/04/15/11493.aspx vss binding remover on developer’s machines to get rid of .scc files

    LDAP Query to search a user in AD using his partial last name

    Dim User as object

    Set User = GetUserObjectFromPartialName(‘doe’)

    Msgbox User.FullName & User.sAMAccountName

    —————————————————————————————————-

    Public Function GetUserObjectFromPartialName(ByVal PartialName As String) As Object
    On Error Resume Next
    Set rs = CreateObject(“adodb.recordset”)
    rs.ActiveConnection = “provider=adsdsoobject”

    rs.Open “<LDAP://dc=sl,dc=ad,dc=csx,dc=com>;(&(objectCategory=Person)” & _
    “(objectClass=OrganizationalPerson)(name=” & PartialName & “*));adspath;subtree”

    If Not rs.EOF Then
    Set GetUserObjectFromPartialName = GetObject(rs(0))
    End If
    End Function

    Recursive LDAP function to get nested groups

    Here is a simple recursive function that I wrote which will give you nested groups and members for any given Active Directory group. Try it….it works! U can bind it to a tree later on to show it on the screen. I have also included an output of how it looks when bound to an iewc Treeview.

    tree.jpg

    Dim AdsPath as string
    Dim XMLRoles as string

    AdsPath = GetAdsPathOfGroupThroughADO(“Domain Admins”)

    XMLRoles = GetRoleMembers(Adspath)

    ———————————————————————–

    Public Function GetAdsPathOfGroupThroughADO(ByVal Group As String) As String
    On Error Resume Next
    Set rs = CreateObject(“ADODB.RecordSet”)
    rs.Open “;(sAMAccountName=” & Group & “);adspath”, “provider=ADsDSOObject”

    If Not rs.EOF Then
    s = rs(0).Value
    End If

    GetAdsPathOfGroupThroughADO = s
    End Function
    ———————————————————————–

    Public Function GetRoleMembers(ByVal RoleAdsPath As String) As String
    Dim eu As Object
    Dim XML As String

    Set eu = CreateObject(“ess.user”)
    Set Group = GetObject(RoleAdsPath)
    XML = “”

    For Each member In Group.Members
    If member.Class = “Group” Then
    XML = XML & vbCrLf & GetRoleMembers(member.ADsPath)
    ElseIf member.Class = “foreignSecurityPrincipal” Then
    On Error Resume Next
    Set u = GetObject(“LDAP://=” & eu.SidStringToHexString(member.cn) & “>”)
    If Err.Number = 0 Then
    XML = XML & vbCrLf & “”
    End If
    End If
    Next

    XML = XML & vbCrLf & “”
    GetRoleMembers = XML
    End Function

    ———————————————————————–

    input.jpgTreetransform.XSLT
    eg. TreeView1.TreeNodeSrc = “XML returned by GetRoleMembers()….”
    TreeView1.TreeNodeXsltSrc = Server.MapPath(“Treetransform.xslt”)�
    ———————————————————————–

    WordPress statistics not updating with Blogstat, firestat or Statpress

    I moved my WordPress blog to my Home machine recently. The main motivation was to have full control over wordpress. As most of you would already know that WordPress is free!, which means that you can download the entire wordpress software with source code and run it from your home machine. All you need is a webserver. I use IIS but there are several free webservers out there. By the way IIS is also free depending on the operating system you have. eg. Windows XP Pro comes with IIS. Or Windows Vista Business and above also come with IIS.

    Anyway, I installed at least 15 free plugins when I moved my blog to my own machine. Yes, thats what you get for hosting your own blog. If you have a wordpress.com or wordpress.org blog, you will not even see the menu option called ‘plugins’. But, the real power of wordpress lies in plugins. Once you start seeing the plugins available out there, you will literally freak out.

    So, I installed 3 plugins just to track my stats (i.e how many people are visiting my blog, what blog posts they are reading, what country they are comning from, what Google search terms they are using to get to my blog etc etc). But, I was really frustrated the first few days, because all the stats plugins showed me was 0 vistors, 0 hits….and I knew that this couldn’t be true. So, now I am sharing the one line of code which was causing all my stats plugins to malfunction. I found out that the “theme” that I was using for my Blog had a missing line of code in the header.php file. So, I just added this line of code and wallah!!!! all the plugins started showing me stats instantly. This is what I did to start making it work…………

    <div id=”sitetitle”>
    <h1><a href=”<?php bloginfo(‘url’); ?>”><?php bloginfo(‘name’); ?></a></h1>
    <h2><?php bloginfo(‘description’); ?></h2>
    </div>

    <div id=”menu”>
    <ul>
    <li><a href=”<?php bloginfo(‘url’); ?>”>home</a></li>
    <?php wp_list_pages(‘title_li=’); ?>
    </ul>
    </div>
    <?php wp_head(); ?> <– This is the line I changed.

    Leave a comment if this does or doesn’t work for you.

    Follow

    Get every new post delivered to your Inbox.