Monday, March 30, 2009

Passing Variable To SetInterval

Today, I need to rotate the background image using javascript. I use the function setInterval to acheive this. However, I can't pass variable to setInterval as several errors occur.

Here is some websites that talking about this problem:
http://www.bigresource.com/JAVASCRIPTS-Passing-variable-to-setInterval-E2H3OB74.html#Gf8cAgFL

http://alexle.net/archives/169

PS: better use anonymous function to deal with it
For example,
setInterval(function(){alert(variable_a);}, 500);

Sunday, March 29, 2009

Internet Explorer Collection helps you test your webpages in different IEs

Each IE version in the collection has already built in the IE developer Toolbar to help developers to fix problems.

Download link:
http://finalbuilds.edskes.net/iecollection.htm

Tuesday, March 24, 2009

Cheaters turn to Web to game certification system

March 24, 2009 — Don't judge a developer by his or her certifications. Cheaters are coordinated, and the answers to exams are easily located on the Web.

Websites, including certcollection.org, examcollection.com and (until recently) sadikhov.com, host forums where members share advice, experience, and even actual word-for-word Microsoft certification test questions known in the cheating community as "MS brain dumps."

Read on:
http://www.sdtimes.com/link/33359

Server Application Unavailable

I wrote this post on my blog on how to resolve the generic Server Application Unavailable message we sometimes get as ASP.Net developers:

If you have ever received an error message on a .Net application that simply stated "Server Application Unavailable" you might find this useful.

When you receive this error, make sure to check the event viewer on the server. This is found under administrative tools. Under the application event log, you will likely find an error that states: "It is not possible to run two different versions of ASP.NET in the same IIS process. Please use the IIS Administration tool to run the application in a separate process."

An application pool is a process that responds to web requests under IIS. An application pool does not have a setting for what type of ASP.Net applications will be run in it. Instead, it loads the appropriate libraries when an ASP.Net application is loaded in the process. Because the libraries for ASP.Net 1.1 and ASP.Net 2.0 are similar, but not the same, the application pool cannot respond to requests for both types of applications at the same time. This can cause sporadic behaviour if you are using the server at the same time as another developer and you have applications using different versions of the framework in the same application pool.

Make sure that on your server there is an application pool dedicated to ASP.Net 2.0 applications and one for ASP.Net 1.1 applications. When you add an ASP.Net application to the server, make sure you select the right application pool for it.

http://forums.asp.net/t/1070357.aspx

Tuesday, March 17, 2009

TryParse, TryParseExact for conversion in .net

Today, I discover a userful function called TryParse in .net programming.

Previously, if we want to convert a string to integer, we will:
Convert.ToInt32(sampleString);

However, we need to catch the Exception if the variable cannot be casted into integer. With the use of TryParse(), it will return false if the variable cannot be parsed:
int.TryParse(sampleString);

It saves some work and makes the code nicer. Also, catching exception is consuming. So TryParse() is really a good tool to use.

Saturday, March 14, 2009

Write a program in 30 minutes (for a C# programmer candidate interview question).

http://stackoverflow.com/questions/156893/write-a-program-in-30-minutes-for-a-c-programmer-candidate-interview-question#156931

JQuery: Manipulate items in dropdownlist

To select items in dropdownlist, we have several ways.

1. Select items by setting the selected value
$('#dropdown').val('option1');

2.Select items by setting the selected index
$('#dropdown').attr("selectedIndex", 3);


To add items (option) in dropdownlist:
$('#dropdown').append($('').val(val).html(html));

Check whether an item (option) is exist in the dropdownlist:
$('#dropdown option[value= yourvalue]').length > 0

Friday, March 13, 2009

JQuery Plugin: BlockUI

The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser[1]. When activated, it will prevent user activity with the page (or part of the page) until it is deactivated. BlockUI adds elements to the DOM to give it both the appearance and behavior of blocking user interaction.

http://www.malsup.com/jquery/block/

Thursday, March 12, 2009

An example of communication between JavaScript and Adobe Flash Player

Today, my project needs to send information from javascript to Flash. Read on the following article:

An example of communication between JavaScript and Adobe Flash Player


http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683

Added: 2009-03-20

The code in the above link does not work. Some modifications are needed:

function getFlashMovie(movieName) {

if(document.embeds[movieName]) return document.embeds[movieName];
if(window.document[movieName]) return window.document[movieName];
if(window[movieName]) return window[movieName];
if(document[movieName]) return document[movieName];
return null;
}

HTTP Handlers and HTTP Modules Overview

To learn about HTTP Handlers. Read on:

http://msdn.microsoft.com/en-us/library/bb398986.aspx

How to: Register HTTP Handlers

http://msdn.microsoft.com/en-us/library/46c5ddfy.aspx


Creating an ASHX handler in ASP.NET:

http://www.aspcode.net/Creating-an-ASHX-handler-in-ASPNET.aspx

Wednesday, March 11, 2009

Add Event Listener in Javascript

Mozilla firefox Developer Center example and usage:

https://developer.mozilla.org/En/DOM/Element.addEventListener

------------------------------------------------------------------------------

Another example for this:

// Cross-browser implementation of element.addEventListener()
// Usage: addListener(window, 'load', myFunction);

function addListener(element, type, expression, bubbling){
bubbling = bubbling false;
if(window.addEventListener) { // Standard
element.addEventListener(type, expression, bubbling);
return true;
} else if(window.attachEvent) { // IE
element.attachEvent('on' + type, expression);
return true;
}
else return false;
}


http://snipplr.com/view.php?codeview&id=561

Great Posts for learning Javascript

Douglas Crockford's Blog

http://javascript.crockford.com/

What ASP.NET Developers Should Know About JavaScript

http://odetocode.com/Articles/473.aspx


Closure On JavaScript Closures

http://odetocode.com/Blogs/scott/archive/2007/07/09/11077.aspx

A Good Example:

http://stackoverflow.com/questions/643542/doesnt-javascript-support-closures-with-local-variables


Function.apply and Function.call in /javaScript

http://odetocode.com/blogs/scott/archive/2007/07/04/11067.aspx

Function.apply, Function.call and Argument list in JavaScript

I have just read about the function.apply and function.call in Scott Allen's post. It's a very useful post talking about the details of how to use it.

Do you know what the following code means?

function sample(message) {
alert(this.toString());
alert(arguments.length);
alert(arguments[0] + arguments[1]);
}

function sample2(object, func, args){
func.apply(object, args);
}

function sample3(message1, message2){
alert(this.toString() + message1 + message2);
}
var text = "Do you understand the code?";
sample.call(text, "Text 1", " and some more text");
alert("Running Sample 2");
sample2(text,sample3,[" Yes", ", I do"]);


Just read and learn:
http://odetocode.com/blogs/scott/archive/2007/07/04/11067.aspx

Multiple cookies with same name

These days I encountered a situation that I cannot set and get a cookie's value properly.

I used Fiddler tool to check about the cookie value and discover that there are two cookies with same name. I didn't realize what's the problem initially and tried to set it expire. But it still doesn't work.

Finally, after searching in Google, I realize that multiple cookies can have same name but in different path. What I need to do is to set the path when setting the cookie's value. For example,

document.cookie = "login=" + loginName + ";path=/";

If you don't set the path, you may have two cookies, one in your root directory and one in your sub-directory.

This is also a reminder for me not to have this mistake again.

Sunday, March 8, 2009

Google Webmaster Central Blog

http://googlewebmastercentral.blogspot.com/

Canonical Tag for SEO

Last week Google, Yahoo, and Microsoft announced support for a new link element to clean up duplicate urls on sites. The syntax is pretty simple: An ugly url such as http://www.example.com/page.html?sid=asdf314159265 can specify in the HEAD part of the document the following:
< link rel="canonical" href="http://example.com/page.html">
That tells search engines that the preferred location of this url (the “canonical” location, in search engine speak) is http://example.com/page.html instead of http://www.example.com/page.html?sid=asdf314159265 .

Reference:
http://www.mattcutts.com/blog/canonical-link-tag/


http://searchengineland.com/canonical-tag-16537


URL Referrer Tracking

http://janeandrobot.com/post/URL-Referrer-Tracking.aspx