Friday, December 31, 2010

What is the difference between String and string in C#

string :
------

The string type represents a sequence of zero or more Unicode characters. string is an alias for String in the .NET Framework.

'string' is the intrinsic C# datatype, and is an alias for the system provided type "System.String". The C# specification states that as a matter of style the keyword ('string') is preferred over the full system type name (System.String, or String).

Although string is a reference type, the equality operators (== and !=) are defined to compare the values of string objects, not references. This makes testing for string equality more intuitive. For example:


String :
------

A String object is called immutable (read-only) because its value cannot be modified once it has been created. Methods that appear to modify a String object actually return a new String object that contains the modification. If it is necessary to modify the actual contents of a string-like object


Difference between string & String :
---------- ------- ------ - ------

the string is usually used for declaration while String is used for accessing static string methods

we can use 'string' do declare fields, properties etc that use the predefined type 'string', since the C# specification tells me this is good style.

we can use 'String' to use system-defined methods, such as String.Compare etc. They are originally defined on 'System.String', not 'string'. 'string' is just an alias in this case.

we can also use 'String' or 'System.Int32' when communicating with other system, especially if they are CLR-compliant. I.e. - if I get data from elsewhere, I'd deserialize it into a System.Int32 rather than an 'int', if the origin by definition was something else than a C# system.

Wednesday, December 29, 2010

Default text disappear from textbox with javascript

//form action="http://www.domain.com" method="post">
//input type="text" size="25" value="Enter Your Default Text Here" onFocus="if(this.value == 'Enter Your Default Text Here') {this.value = '';}" //onBlur="if (this.value == '') {this.value = 'Enter Your Default Text Here';}" />
//input type=submit value=Submit>
///FORM>

Monday, December 27, 2010

Javascript Open a Window Full Size (Mazimized)

function f_open_window_max( aURL, aWinName )
{
var wOpen;
var sOptions;

sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

wOpen = window.open( '', aWinName, sOptions );
wOpen.location = aURL;
wOpen.focus();
wOpen.moveTo( 0, 0 );
wOpen.resizeTo( screen.availWidth, screen.availHeight );
return wOpen;
}

Thursday, December 23, 2010

Javascript function for horizontal center align in asp.net

function SetDivPosition(tbl,hgt)
{
document.getElementById(tbl).style.height = ((document.body.clientHeight - hgt)/2) + "px";

}

//Call this function into the OnLoad() and OnResize() event of body tag.

Wednesday, December 15, 2010

Difference between Website and Web Application in ASP.NET

Web site in Visual Studio 2005:


A web site is just a group of all files in a folder and sub folders. There is no project file. All files under the specific folder - including your word documents, text files, images etc are part of the web site.

You have to deploy all files including source files (unless you pre compile them) to the server. Files are compiled dynamically during run time.

To create a "web site", you need to use the menu File > New > Website

You will have the option to choose either one of the following location types:

# File System - Allows you to choose a folder to put all the files.
# Http - Allows you to choose a virtual directory to put the files.
# FTP - Allows you to choose an ftp location.

In any of the above cases, no project file is created automatically. Visual Studio considers all files under the folder are part of the web site.

There will be no single assembly created and you will nto see a "Bin" folder.

The benefits of this model is, you do not need a project file or virtual directory to open a project. It is very handy when you share or download code from the internet. You just need to copy the downloaded code into a folder and you are ready to go!




Web Application Project in Visual Studio 2005:


Microsoft introduced the "web site" concept where all files under a web site are part of the site, hoping that the development community is going to love that. In fact, this is very usefull to share code.

However, they did not consider millions of existing web applications where people are comfortable with the "project" based application. Also, there were lot of web applications where several un wanted files were kept under the web site folder. So, the new model did not work well for them.

When people started screaming, Microsoft came up with the answer. On April 7, 2006, they announced "Visual Studio 2005 Web Application Projects" as an Add-On to Visual Studio 2005. This Add-On will allow you to create and use web applications just like the way it used to be in Visual Studio 2003.

The Visual Studio 2005 Web Application Project model uses the same project, build and compilation method as the Visual Studio .NET 2003 web project model.

All code files within the project are compiled into a single assembly that is built and copied in the Bin directory.

All files contained within the project are defined within a project file (as well as the assembly references and other project meta-data settings). Files under the web's file-system root that are not defined in the project file are not considered part of the web project.