Friday, November 16, 2007

Datagrid VS ViewState

This week, I try to optimized my web application which using 10 million record.

The first thing that I notice that EnableViewState by default is set to true.

So my datagrid will store all the view state into client. so every time there is postback or asyn postback, it will transfer heaps of data through networks. and It is not very efficient.

So I try to disable them by EnablingViewState = false.
However by disabling view state in the data , all the events in datagrid is not fired..


one of the solution is to disable view state on each item.
_dg.DataBind();
foreach (DataGridItem item in _dg.Items)
{
item.EnableViewState=false;
{


however, if your all commandArguments is not work,..

so the other solution is you need to bind every time in page back...

Tuesday, November 6, 2007

Resurrection

Just in case if you don't know.

Sometimes it is you may need to resurrects your object.
for example you want the object to clean itself gracefully everytime the object dies.

Here how to do resurrection....

public class MyBaseClass
{
Protected override void Finalize()
{
//TODO: Some Clean up....

GC.ReRegisterForFinalize(this);
}
}

By calling GC.ReRegisterForFinalize method, it will appends the address of the specified object to the end of the finalization queue. When GC detects that this object is unreadchable again, It will queue the object's pointer ob the freachable queue and Finalize method will get called again.

This is example show how to create an object that constantly resurrects itself and never dies...
which usually undesireable. It is far more common to conditionally set a root to a reference the object inside the finalize method.