Wednesday, September 23, 2009

On button click - how to bring up browsers emailing box using javascript.

INPUT TYPE="button" VALUE="Send Email." onClick = "parent.location= 'mailto:mymailid@gmail.com'"

Show Timer on status bar using Javascript

function showtime ()
{

var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M." : " A.M."

window.status = timeValue;

}

Call this function on load of the form.

Tuesday, September 22, 2009

Check the browser type using javascript.

if(navigator.appName=="Netscape")
{
alert("Browser is Netscape Navigator.");
}
else if (navigator.appName == "Microsoft Internet Explorer")
{
alert("Browser is Microsoft Internet Explorer.");
}
else
{
alert("Neither Netscape Navigator nor Internet Explorer.");
}

Thursday, September 10, 2009

Year is a leap year or not.

Suppose you want to know if 2009 is a leapyear or not.
Use:
bool Result = DateTime.IsLeapYear(2009);

Get the IP address based on the host name

using System.Net;

string HostName = Dns.GetHostName(); //for local machine
public string GetIPAddress(string HostName)
{
IPHostEntry ipHostEntry = Dns.GetHostByName(HostName);
IPAddress [] addres = ipHostEntry.AddressList;
string IPAddress = addres[0].ToString();
return IPAddress;
}

Interface members can be Properties.

Syntax:
interface ICalculate
{

int Height
{
get;
set;
}

int Width
{
get;
set;
}

float Area();

}

Set Control Focus using Javascript code.

body onload="document.forms[0]['TextBox1'].focus();"

Wednesday, September 9, 2009

What are indexers?

Indexers are similar to properties except that the get and set accessors of indexers take parameters while property accessors do not.

Destructor and finalize

In C# you can never call destructors, the reason is one cannot destroy an object. GC destroys the objects only when necessary. Some situations of necessity are memory is exhausted or user explicitly calls System.GC.Collect() method.
Points to remember:
1. Destructors are invoked automatically and cannot be invoked explicitly.
2. Destructors cannot be overloaded. Thus a class can have, at most, one destructor.
3. Destructors are not inherited. Thus a class has no destructors other than the one which may be declared in it.
4. Destructors cannot be used with structs. They are only used with classes.
5. An instance becomes eligible for destruction when it is no longer possible for any code to use the instance.
6. Execution of the destructor for the instance may occur at any time after the instance becomes eligible for destruction.
7. When an instance is destructed, the destructors in its inheritance chain are called in order from most derived to least derived.