DOT NET – How to make a button as default button and set Focus on a particular text box

In the initial days when i was new to development side and in some site i used to login straight away when i enter username and password and hit Enter key on my keyboard.

I used to think how is this happening but never had any answer but now i am going to show how thats possible.

In this post I will be talking about how  to make any button Default button and set Focus on a particular text box in any page thats displayed.

Ex: Make a test site and go to default.aspx

Step 1:

in <body> tag write the following code


<form id=”frmExample” runat=”server” defaultbutton=”btnLogin” defaultfocus=”txtUserName”>

<table><tr><td width=”50%”>

Welcome to the Example Web site from dilip


<td width=”50%”>


<tr><td><asp:TextBox ID=”txtUserName” runat=”server” Text=”UserName” /></td><td><asp:TextBox ID=”txtPassword” runat=”server” Text=”Password”/></td></tr>

<tr><td><asp:Button ID=”btnLogin” runat=”server” Text=”Login” onclick=”btnLogin_Click”/></td><td><asp:Button ID=”btnSignIn” runat=”server” Text=”Signup”/></td></tr>







Note: Here the beauty is that i have login and singnup button and i made defaultbutton as login button, and defaultfocus on username text box so whenever this page is viewed from any web browser focus will be on username text box and default button will be login button so when u hit enter it will invoke login button so simple.

 Step 2: see  carefully i have a function onclick=”btnLogin_Click” now press F7 key and go to .cs side of the same page or right click on the mouse and select view code .

and write the following code in .cs side

protected void btnLogin_Click(object sender, EventArgs e)


Response.Write(“Default Button was clicked and u are now logged In”);



Note: Here another concept when ever you enter key this method will be invoked and at the same time there wont be any other you can see that means response is closed just to make you feel that you really logged in but actually u are in same page.

the output is some this like this :

First Time when visited:

you can see username text box is in focus.

Then when enter key is pressed:

Reference : Dilip Kumar Jena ( )

DOT NET – Difference between string and string builder

In Dot Net there will be many cases where in we need to operate on strings and first thing we remember is using system.String but there are certainly many points we need to remember and consider before we operate on strings.

1) Performance.

2)how many times we need to concatenate.

Lets take an example for concatenate five strings.

EX 1. Using System.String

System.String str =“My Name is dilip”;

str += “and i am”; str += “working on “;

str += “Post of “;

str += “difference between string and string builder”;


and the expected output well you probably guessed it right

“My Name is dilipand i amworking on Post of difference between string and string builder”

Now what has happed? yes the important question now how many times we have appended the str variable those number of times string was created in memory location and abandoned when a new string is created and later waiting for garbage collection.

This leads to memory wastage and degradation of performance because string are immutable(that means any change to string causes a runtime to create a new string and abandon old one).

Think about the situation where in u need to work on 100 or more strings????

Dot Net has answer for it in the form of System.Text.StringBuilder class

EX2. Same Example using StringBuilder

StringBuilder sb = new StringBuilder();

sb.Append( “My Name is dilip”);

sb.Append( “and i am”);

sb.Append( “working on “);

sb.Append( “Post of “);

sb.Append( “difference between string and string builder”);

and the output is same as previous

“My Name is dilipand i amworking on Post of difference between string and string builder”

But this time there was only one string created in memory dynamically and modified as we append the new string, by this there is not much garbage collection and also helps improve performance. Append is taken only for example there are a lot of other functions which are just waiting for you to invoke.Happy coding.

Reference : Dilip Kumar Jena ( )

DOT NET – What is a cookie

Recently I got a message from one of the reader of my site that what exactly is a cookie. So I decided to wire a post dedicated to it .

  1. A cookie is name=value pair like variable which is stored as a file(persistant cookie) and which travels automatically between every request and response.
  2. Cookies are based on domains(website). As long as user is working with current web site cookie will be available.
  3. Cookies are maintained by browser but not by server which means cookies based websites are dependent on client.
  4. Cookies can be created as
    (i) In-memory cookie
    (ii) Persistant Cookie

An In-memory cookie means as long as user is working with app it will be available – also called as Session Cookie.

Persistant cookie means it will be stored in client physical location and available online as well as offline.

Reference : Dilip Kumar Jena ( )

DOT NET 4.0 – Concerns and criticisms relating to .NET

Here are most known Criticisms

  • Applications running in a managed environment such as the Microsoft framework’s CLR or Java’s JVM tend to require more system resources than similar applications that access machine resources more directly. Some applications, however, have been shown to perform better in .NET than in their native version. This could be due to the runtime optimizations made possible by such an environment, the use of relatively well-performing functions in the .NET framework, just-in-time compilation of managed code, or other aspects of the CLR.


  • As JIT languages can be more easily reverse-engineered than native code to algorithms used by an application there is concern over possible loss of trade secrets and the bypassing of license control mechanisms. Many obfuscation techniques already developed, however, can help to prevent this; indeed Microsoft’s Visual Studio 2005 includes such a tool.


  • In a managed environment such as the Microsoft framework’s CLR or Java’s JVM the regularly occurring garbage collection for reclaiming memory suspends execution of the application for an unpredictable lapse of time (typically no more than a few milliseconds).


  • Since the framework is not pre-installed on older versions of Windows an application that requires it must verify that it is present, and if it is not, guide the user to install it.


  • Newer versions of the framework (3.5 and up) are not pre-installed on any versions of the Windows operating system. Some developers have expressed concerns about the large size (around 54 MB for end-users with .NET 3.0 and 65 MB with .NET 3.5).

Reference : Dilip Kumar Jena ( )


DOT NET 4.0 – Features of DOT NET


Because interaction between new and older applications is commonly required, the .NET Framework provides means to access functionality that is implemented in programs that execute outside the .NET environment. Access to COM components is provided in the System.Runtime.InteropServices and System.EnterpriseServices of the framework.


Common Runtime Engine

Programming languages on the .NET Framework compile into an intermediate language known as the Common Intermediate Language (CIL). In Microsoft’s implementation this intermediate language is not interpreted but rather compiled in a manner known as just-in-time compilation (JIT) into native code.


Language Independence

The .NET Framework introduces a Common Type System, or CTS. The CTS specification defines all possible datatypes and programming constructs supported by the CLR and how they may or may not interact with each other. Because of this feature, the .NET Framework supports the exchange of instances of types between programs written in any of the .NET languages.


Base Class Library

The Base Class Library (BCL), part of the Framework Class Library (FCL), is a library of functionality available to all languages using the .NET Framework. The BCL provides classes which encapsulate a number of common functions.


Simplified Deployment

Installation of computer software must be carefully managed to ensure that it does not interfere with previously installed software, and that it conforms to increasingly stringent security requirements. The .NET framework includes design features and tools that help address these requirements.



The design of the .NET Framework allows it to theoretically be platform agnostic, and thus cross-platform compatible. That is, a program written to use the framework should run without change on any type of system for which the framework is implemented. Microsoft’s commercial implementations of the framework cover Windows. In addition, Microsoft submits the specifications for the Common Language Infrastructure (which includes the core class libraries, Common Type System, and the Common Intermediate Language), the C# language to both ECMA and the ISO, making them available as open standards. This makes it possible for third parties to create compatible implementations of the framework and its languages on other platforms.


Memory management

It is the act of managing computer memory. In its simpler forms, this involves providing ways to allocate portions of memory to programs at their request, and freeing it for reuse when no longer needed.

The management of main memory is critical to the computer system. In this process it uses the Garbage Collection which is the automated allocation, and deallocation of computer memory resources for a program.

This is generally implemented at the programming language level and is in opposition to manual memory management, the explicit allocation and deallocation of computer memory resources.

In computer science, garbage collection (GC) is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory used by objects that will never be accessed or mutated again by the application. Garbage collection was invented by John McCarthy around 1959 to solve the problems of manual memory management.

Reference : Dilip Kumar Jena ( )

DOT NET 2.0 – Features of C# 2.0

New features in C# for the .NET SDK 2.0 (corresponding to the 3rd edition of the ECMA-334 standard) are:

  • Partial classes allow class implementation across more than one source file. This permits splitting up very large classes.
  • Generics or parameterized types.
  • Static classes that cannot be instantiated, and that only allow static members. This is similar to the concept of module in many procedural languages.
  • Anonymous delegates.
  • The accessibility of property accessors can be set independently.
  • Nullable value types which provides improved interaction with SQL databases.
  • Coalesce operator: (??) returns the first of its operands which is not null (or null, if no such operand exists):

Reference : Dilip Kumar Jena ( )

DOT NET 4.0 – Design goals for C#.NET

The ECMA standard lists these design goals for C#:

  • C# is intended to be a simple, modern, general-purpose, object-oriented programming language.
  • Because software robustness, durability and programmer productivity are important, the language should include strong type checking, array bounds checking, detection of attempts to use uninitialized variables, source code portability, and automatic garbage collection.
  • The language is intended for use in developing software components that can take advantage of distributed environments.
  • Programmer portability is very important, especially for those programmers already familiar with C and C++.
  • Support for internationalization is very important.
  • C# is intended to be suitable for writing applications for both hosted and embedded systems, ranging from the very large that use sophisticated operating systems, down to the very small having dedicated functions.

Reference : Dilip Kumar Jena ( )