Friday 28 October 2011

Javascript to disable all ASP:ImageButton

if you want to disable all <ASP:ImageButton type controls using Javascript, you have to keep in mind that browser renders the controls this way

<input type="image" name="ctl00$btnUserHistory" id="btnUserHistory" title="User Activities" src="/Img/userhistory.gif" />

You see ctl00$ in the name as the button is inside a ContentPlaceHolder, so catch all inside or not write this function

function disableButton() {
        //Disable All Image Buttons       
        var ButtonsColl = document.getElementsByTagName('input');
        for (i = 0; i <= ButtonsColl.length - 1; i++) {
            if (ButtonsColl[i].getAttribute('type') == 'image') {
                ButtonsColl[i].disabled = true;
            }
        }
    }

Tuesday 25 October 2011

Convert SSL Certificate .cer to .pfx

If you were like me working on Azure projects and suddenly was required to upload your SSL certificate and hit the dead end trying to figure out how to convert the file to .pfx, you have come to the right place, follow these simple steps and you'll be good to go.

PowerShell Script
$c = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("c:\mycert.cer")
$bytes = $c.Export("Pfx","password")
[System.IO.File]::WriteAllBytes("c:\mycert.pfx", $bytes)

and just incase if you got the error cannot find type [System.Security.Cryptography.X509.....

Try running this to see if you have the System.dll loaded (should be by default):
[AppDomain]::CurrentDomain.GetAssemblies() |
    Where {$_.Location -match '\\System\\'}

If it is loaded then this command should show the X509Certificate2 type:
[AppDomain]::CurrentDomain.GetAssemblies() |
Where {$_.Location -match '\\System\\'} |
%{$_.GetExportedTypes()} | Where {$_.Name -match 'X509Cert'}
If the System.dll isn't loaded (which would be odd) try loading it:
Add-Type -AssembyName System

Thursday 6 October 2011

Changing License option of Windows Server

Just incase if you have installed the Windows Standard Server, and wanted to know how to convert the license to Enterprise here is the command line:

DISM /online /Set-Edition:ServerEnterprise /ProductKey:xxxxx-xxxxx-xxxxx-xxxxx-xxxxx