Tuesday, December 30, 2008

Client Side Post Back

The simple code that will postback the page from client side is shown below.

__doPostBack('control_clientID','OnClick');

The first parameter is control's ID and the second one is argument passed which can be accessed on the server side. The controlID and argument is populated in the page's hidden variable __EVENTTARGET and __EVENTARGUMENT respectively. The values can also be accessed from Forms/Param collection as below,
string controlID = Request.Params.Get("__EVENTTARGET");
will get us the control that caused the postback.

Button and ImageButton are not supported under this because they don't call __doPostBack method call in their html page(if View Souce is seen) and so the __EVENTTARGET variable is empty.

Friday, December 19, 2008

Health Monitoring

A simple code, that generates email to an admin with a detailed report on an unhandled exception in our dotnet code, thanks to heathmonitoring property in web.config.

The following is the configuration required to setup healthmonitor of an application.

Thursday, December 18, 2008

Registering UserControl in web.config

User controls are quite commonly used in our asp.net pages. The purpose of that is mainly, code ones and use in many pages. Of course, the page should be decorated with @Register directive pointing that usercontrol location. Say, if the name of the usercontrol is changed, then it has to be changed in as many pages it has been decorated and it becomes bit complex.

But declaring usercontrol in web.config avoids declaring in .aspx pages therby avoiding decoration @Register directive in many .aspx pages.

Registering in web.config is shown below-


Using the Usercontrol registered in web.config

Wednesday, December 3, 2008

Difference Between Convert.ToString() and .ToString()

string stringVariable = null;
string stringHolder = stringVariable.ToString();
While in runtime suppose “stringVariable” happens to get “null” assigned we get “Object reference not set to an instance of an object.” exception.


string stringVariable = null;
string stringHolder = Convert.ToString(stringVariable);
While using the above snippet, even if “stringVariable” gets assigned “null” Convert.ToString() with return “”(an empty string) by avoiding exception.

So, better to use Convert.ToString() instead of .ToString()