Thursday 30 April 2009

Error On Install: "Installation User Interface Option"

I had a problem installing a new version of a windows application, even after I uninstalled all previous versions. I toyed the following steps, but I had to search the registry myself with the produce code form the MSI project in .Net. Just deleted the whole folder once it was found.

Here a snippet of the web page I found with the solution:

If the application is a Windows or Web application -

1. Go to START, RUN and type the following: MSIEXEC /X "path to the .MSI
file you
want to uninstall" and click OK.
2. After the application is uninstalled, try installing your MSI file
again. If you
get the same error, then some portion of the application still exists on
the
machine. You will want to use MSIZAP to remove the product, or you can
search for
the PRODUCTID of the msi package in the registry and remove the associated
registry
keys. The Product ID looks like {xxxxx-xxxxx-xxx-xxxxx-xxxxx}


Link to source: http://www.tech-archive.net/Archive/VisualStudio/microsoft.public.vsnet.general/2005-10/msg00086.html

Wednesday 29 April 2009

Website Accessibility

There are no set laws in the UK regarding Website Accessibility, but your website should at least meet Priority Level 1 and it is recommended to meet Priority Level 2.

Her is the link to Website Accessibility Level 1 (A) reference:

http://www.w3.org/WAI/WCAG20/quickref/Overview.php

Using multiple versions of browsers (IE + FF)

Internet Explorer


I found this handy tool, IETester, for testing your websites in multiple versions of IE, each in a different tab. Currently it can test IE 5.5, 6, 7 and 8 beta.

Since it's an early alpha release there is a list of known bugs on their homepage but it is good enough to view pages in.

Firefox


I found the easiest way of testing in various versions of FF was to use a portable version since it doesn't need any installation and won't mess with whichever current install you have.

You can find all portable legacy versions if FF here.

Tuesday 28 April 2009

Extension Methods in C# 3.0

A new function of C# 3.0 is Extension Methods.

"Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type."

For example, if you wanted a method to convert a temperature from celsius to fahrenheit, where previously you would use

int temp = 30;
int i = myClass.CelsiusToFahrenheit(temp);


using extension methods you can now use

int temp = 30;
int i = temp.CelsiusToFahrenheit();

To do this you would create a new static class to contain the static method CelsiusToFahrenheit. The key to extension methods is passing in the this keyword along with the variable. For example,


public static class myClass
{
public static int CelsiusToFahrenheit(this int temp)
{
return (9 / 5) * temp + 32;
}
}


This will now allow you to use the CelsiusToFahrenheit method on any integer variables.

You can also add methods to extend your own custom classes, and the methods can have different return types. For example, if you have your own class, TestClass, you can create a static method using extending TestClass, e.g.


public static DateTime doSomething(this TestClass t)
{
//do something
}


Which will then allow you to use:

TestClass t = new TestClass();
DateTime x = t.doSomething();

Monday 27 April 2009

jQuery events not firing for dynamic content

When adding dynamic content (using AJAX or DOM modification) using jQuery, events are not fired for the new objects, for example if you have the following html:

<button id="load" href="#">Test</button>
<div id="container"></div>


When I click the load button I want to add a link to another page inside the container DIV, so I use the following jQuery.


$(function() {
$("#load").click(function() {
$("#container").html("<a id='popup' href='contactForm.html'>popup</a>")
});

$("#popup").click(function(){
alert("Clicked");
return false;
});
});


The click event for the dynamically created anchor tag (id="popup") will not fire using the above because this code is run once the document is ready, and at that time jQuery will look for an object with an Id of popup which doesn't exist yet.

I've found a few different ways to do this:

1. Add a generic click event for the body tag and check what was clicked, for example:


$("body").click(function(e){
var target = $(e.target);
if (target.is("#popup")) {
alert("Clicked");
return false;
}
});


Using this example you check what was clicked using target.is(), you can use any valid CSS selector statements to check the item clicked. This way is simple to implement but can quickly grow if you have a lot of dynamic content.

2. Use the live command, which will tell jQuery to bind any current and future references of "#popup" to the click event.



$("#popup").live("click",function(){
alert("Clicked");
return false;
});



The following 3 ways are variations on the same theme in that the events are bound after content creation.

3. Use the jQuery Bind command to bind the click event to a particular function on creation. e.g.:


$("#load").click(function(){
$("#container").html("<a id='popup' href='contactForm.html'>popup</a>").bind('click', loadClick);
//can also use
//$("#container").html("<a id='popup' href='contactForm.html'>popup</a>").click(loadClick);
});

function loadClick(){
alert("Clicked");
return false;
}


4. Insert the function for handling the click event within the initial click event when you create the popup link. This runs the event binding as soon as the item is added.


$("#load").click(function(){
$("#container").html("<a id='popup' href='contactForm.html'>popup</a>");
$("#popup").click(function(){
alert("Clicked");
return false;
});
});


5. Similar to the above method except this way you create a method which does all data binding (bindEvents()). This can be useful if you have a lot dynamic content that needs to be bound at the same time, it can be encapsulated into 1 event.


$("#load").click(function(){
$("#container").html("<a id='popup' href='contactForm.html'>popup</a>");
bindEvents();
});

function bindEvents(){
$("#popup").click(function(){
alert("Clicked");
return false;
});
};



There's also a plugin called livequery that makes binding easier.

Sunday 26 April 2009

Firebug for all browsers!

When designing websites I've found firebug for FireFox invaluable for checking out exactly what's going on. I've now found you can get Firebug lite for use on any browser!

It's very easy to use, all you have to do is include the following code in any page that you want to use it in:
<script type="'text/javascript'" src="%27http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js%27"></script>

Genius.

Wednesday 1 April 2009

TSQL script to loop round all databases

Hi Guys

Quick script to loop round all databases and perform an action - in this case its setting all databases to simple recovery. The keyword here is sp_msforeachdb - pure genius :)

use master
GO
sp_msforeachdb '
declare @sql VARCHAR(1000)
IF DATABASEPROPERTYEX(''?'', ''Rjavascript:void(0)ecovery'') <> ''SIMPLE''
begin
set @sql = ''ALTER DATABASE ? SET RECOVERY SIMPLE''
PRINT @sql

end'
Free Hit Counter