Friday, July 30, 2004

VJs Tip Of The Day - July 30th 2004

Global Asssembly Cache (GAC) & CLR

When your assembly is ready to go to GAC (implies you need to do some steps like strong name generation etc, before it can... :-) ) you can use Gacutil.exe provided by .Net Framework SDK to install your assembly into GAC...
Alternatively you can just drag and drop an assembly in "WINNT\ASSEMBLY" folder in your windows explorer; The CLR does run the Gacutil in the back-ground and so your assembly gets intstalled in the GAC...

PS: The weekend has nearly started so pardon this silly tip... Remember our mass movement: "No working on weekends... Do what you enjoy!!"... Btw, If you find me in office on weekends don't feel I am breaching the contract rather assume that: I enjoy work... :-)

Thursday, July 29, 2004

VJs Tip Of The Day - July 29th 2004

Fragment Caching
Fragment caching is a technique to cache only partial part of the page... This technique is used to improve performance of your page, but it needs to be decided at design time...
You can achieve Fragment caching by developing a part of your web page as User Control... User Control can then cache itself independant of the page... User Controls provides many more benefits other than Fragment Caching so while going for User Controls there are other factors to be considered...

Wednesday, July 28, 2004

VJs Tip Of The Day - July 28th 2004

ASP.Net Server Controls Categories

ASP.Net Server Control can be broadly classified into 4 categories...

  1. Intrinsic Controls -These controls correspond to their HTML counterpart... eg Textbox control, Button control
  2. Data-Centric Controls - These controls are used for data display, binding, modification purposes... They bind to various data sources... eg.  DataGrid control
  3. RichControls - Usually do not have HTML counterparts... These are usually composite controls which in themselves contain other controls... eg. Calendar control
  4. Validation Controls - As the name suggest they are used for validation purposes and can validate many type of user inputs.... eg. RegularExpressionValidator


Tuesday, July 27, 2004

VJs Tip Of The Day - July 27th 2004

SQL Server Session State Does It Again

Well did you wonder yesterday, that if your session data was stored in permanent tables on SQL server and there would be "n" number of sessions running for your application all the time how much data would get collected in the SQL Server???

So, there has to be a mechanism to clean this data every once in a while right!!... And ofcourse there is... When SQL Server support for session gets installed a job to delete the expired session is also installed, this job runs every minute and is called ASPState_Job_DeleteExpiredSessions...; It requires SQLServerAgent service to be running in order to work...

PS: To visit earlier tips click on the right side "Archives" menu of the blog site...

Monday, July 26, 2004

VJs Tip Of The Day - July 26th 2004

Again Session State

Well this time we will get into little details... ASP.Net provides two pair of SQL scripts to create/delete the SQLServer Session DB... The first pair of script creates TempDB where ASP.Net session state is stored, but as the name specifies this DB will loose its value if SQL server is re-started...the script are named InstallSqlState.sql and UninstallSqlState.sql...

If you wish to keep your session data even more secure, you would do so by running the other pair of scripts... These scripts create permanent tables on SQL Server... These scripts are called InstallPersistSqlState.sql and UninstallPersistSqlState.sql... 

All the above mentioned scripts are located in the same folder as the session state NT service...

Friday, July 23, 2004

VJs Tip Of The Day - July 23rd 2004

mode="SQLServer" for sessionState

When you choose your sessionState to be SQLServer, ASP.Net uses the default DB and initial catalogs for storing your session information into SQLServer... That is the reason you are not allowed to pass tokens such as Database and Initial Catalog in the connection string... Finally your entry in the web.config file will look like

                        sqlConnectionString="server=;uid=<user id>pwd<password>" /> 

user id and password can be replaced by integrated security settings...

Thursday, July 22, 2004

VJs Tip Of The Day - July 22nd 2004

Session State in ASP.Net

ASP.Net supports three different providers for Session State... They are:

InProc - Session values are kept live in the memory of ASP.Net worker process
StateServer - Session values are serialized to store in the memory of a seperate proces i.e. aspnet_state.exe
SQLServer - Session values are stored on SQL Server...

You can read more about operational information and performance of session variables at



Wednesday, July 21, 2004

VJs Tip Of The Day - July 21th 2004

Performance with static variables as compared to Application variables

Sometimes if you want to share a value of a type across pages then it is sensible to use static variables instead of Application variable... The advantages from performance perspective by taking this approach are:

Storing and reading a value can be many times faster with static variables as they do not require to lookup into application variables collection when you refer to them...

You also do not need to cast from object to a specific type, as you need to do with Application variables, but you need to make sure that you declare the static variable of same type as the object that needs to be stored... By this you can also avoid the overhead casting, boxing and unboxing...

Monday, July 19, 2004

VJs Tip Of The Day - July 20th 2004


It is possible to forcibly remove a page from output cache... You can do so by a static method called HttpResponse.RemoveOutputCacheItem("Page path")...
If you are running on a web farm environment then you would have to call this method on each server as cache is not shared across servers...

VJs Tip Of The Day - July 19th 2004

DataReader Object
ADO.Net objects are broadly divided into two sections:
Connected Objects
Disconnected Objects
The DataReader is one of the connected objects of ADO.Net... It helps you examine the rows that are fetched by your query, one at a time... It discards every row after you have gone through it and so it is extreamly fast...
It also contains read-only data, so no updates are allowed using DataReader objects...

Friday, July 16, 2004

VJs Tip Of The Day - July 16th 2004

Const vs readonly in C#

const (Constants) are variables whose values are set at compile time, either by the programmer or by the compiler... It cannot be modified there after, so if you need a field whose value is known at compile time and should not be changed anytime later then you should declare that field as const... Intersting note is that const fields are statis by default and so you do not need to instantiate a class to access them...

readonly (Read Only) are variables whose values are set at run time, but only once... The value of such variables are set in the constructors and cannot be modified there on... These variables are useful when you want the value of the variable to be fixed but fixed to a value which is known only at run time...

Now if you need a static variable whose value is known only at runtime then make it static readonly... :-) 

Sudhir from TCS wanted to add the tip above below is his note:
Hi Vishal    a little addition in yr Tip What is the difference between CONST and READONLY? Both are meant for constant values. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used. readonly int b; public X() { b=1; } public X(string s) { b=5; } public X(string s, int i) { b=i; } Also, while a const field is a compile-time constant, the readonly field can be used for runtime constants

Thursday, July 15, 2004

VJs Tip Of The Day - July 15th 2004

MemberwiseClone Method Contd...

Well I got a couple of posts yesterday that if MemberwiseClone method does Shallow Copy, is there anything like Deep Copy... Well these are just terms, if you want the copy of the object also to have copy of all the object it references then we can say that its Deep Copy and to achieve Deep Copy we must implement ICloneable interface in our objects and do manual cloning... :-)

Wednesday, July 14, 2004

VJs Tip Of The Day - July 14th 2004

MemberwiseClone Method

MemberwiseClone Method is a protected method of the object class which all the types in .Net inherit (everthing inherits from Object!!)... This method returns an object and basically does a Shallow Copy of the object, i.e. copy of the object does not contain the copy of the objects it refrences....

Tuesday, July 13, 2004

VJs Tip Of The Day - July 13th 2004

Lazy Initialization

Lazy Initialization is an optimizing technique whereby some of a class's members are not initalized until they are needed...
This is in particular useful when you have class that contains members that are not used often and whose initalization might consume a lot of resources... Some examples would be accessing File System or network objects or databases...

Well you would be doing this already, now you know the technical term for it... :-)

Monday, July 12, 2004

Just for my records

Today was a milestone day... This is good enough to remember... :-)

VJs Tip Of The Day - July 12th 2004

Code Pitching and EconoJITer

EconoJITer is one the three kindof JIT compilers available in .Net... It discards compiled code out of the memory to release some space when system is running on low memory...
EconoJIT compilation is the option which should be chosen when there is scarcity of memory like in case of small handheld devices like Pocket PC, PDA etc...

The process of releasing memory by discarding the already compiled code (from MSIL) is called as Code Pitching

Friday, July 09, 2004

VJs Tip Of The Day - July 9th 2004

HelpProvider Class

HelpProvider Class in Windows form has a method SetHelpString()... This method will associate a string that you provide with the control specified... This help will be shown when the user presses F1 while the control has focus...


Private objhelpProvider As System.Windows.Forms.HelpProvider
Me.objhelpProvider.SetHelpString(Me.txtZipCode, "Just enter the first 5 digits for Zip code, this applies to US only...")
Me.objhelpProvider.SetShowHelp(Me.txtZipCode, True)

Thursday, July 08, 2004

VJs Tip Of The Day - July 8th 2004

Application Domains Basics

Inter process communication is always painful... The memory pointer in one process many a times does not make a lot of sense in the other process... To tackle this problem and many others Application Domains are introduced in .Net... There can be more than one Application Domain running under the same process... Application Domain provides nearly equivalent level of isolation as would a separate process and at the same time saves the hits of cross-process communications... By having high isolation you can prevent failure of one application to affect other application...

Note: There is lot more to application domains and its a very interesting topic, do give it some time of yours it will be worthwhile..

Wednesday, July 07, 2004

VJs Tip Of The Day - July 7th 2004

DataGrid.ItemDataBound Event

The ItemDataBound event is raised after an item is data bound to the DataGrid control... This event provides you with the last opportunity to access the data item before it is displayed on the client. After this event is raised, the data item is nulled or no longer available...

You would land up using this event if you are making changes to the display of your data grid... Read more about the event and sample code in MSDN...

Tuesday, July 06, 2004

VJs Tip Of The Day - July 6th 2004

To utilize the Add/Remove Programs feature in Control Panel, you must add a key to
the Registry under

where UniqueName will be any Unique name that you can use for your program identification

Note: Goto Start->Run = "Regedit" and browse to the location to see for yourself...

Friday, July 02, 2004

VJs Tip Of The Day - July 2nd 2004

<pages> tag in web.config

<pages> element is located at the below defined position in web.config

It contains a attribute called enableSessionState which specifies whether session state is enabled or not.

It can take following three values:
true - Indicates that session state is enabled.
false - Indicates that session state is not enabled.
ReadOnly - Specifies that an application can read but cannot modify session state variables.

Thursday, July 01, 2004

VJs Tip Of The Day - July 1st 2004

Split Functions in .Net

There are multiple Split functions available in .NET...

U can use System.String.Split if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter. Here there are chances of getting white spaces when you would not expect them to come...

Use System.Text.RegularExpressions.RegEx.Split to split based on some specific formats... You can use this in case the earlier one does not work for you...

At the end if you remember the good old days you can reference the Microsoft.VisualBasic assembly in your program and can use the Strings.Split function to split a string based on a word... The favorite way of VB6 programmer... :-)

Just for my records -MCP ASP.Net

Today I used the free coupon, which all MVPs got last year to appear MCP exam... Microsoft wanted their MVPs to be certified... So I fulfilled their wish...

Became MCP in ASP.Net... :-)

PS: Wonder what's the use of the certifications, when such things never ever effect my pay package...