Tuesday, September 30, 2008

Asp.net embraces jquery

Great news for ajax development using JQuery. Microsoft has taken a great step announcing that jquery would be intergated in the new version of Asp.net with intellisense etc. More on Scott's blog.

Monday, September 29, 2008

Hide or change an image if not found on client side

We had a case in a project where images were loaded from external sources and we wanted to hide or change the image on client side with javascipt in case the image is not found or there was an error loading it.

It can be easily done using the "onerror" event with image tag.
For example:

<asp:image id="imgImgMap" onerror="hideImage(this)" runat="server" cssclass="destMapImg">

<script type="text/javascript">
function hideImage() {
//Load another image etc.

Tuesday, September 16, 2008

Default value for a dropdown list

Its a small add-in in Asp.net 2 and later but I find it very useful. If you have a dropdown list which you bind with data from a database or other source and want to add a default item as well like "Please select an item", it could be easily done with a new property AppendDataBoundItems property of dropdownlist. Simply set it to true while declaring the list and add you default item in it.

When you will this list with a data source the first item would still be there.