Tuesday, April 22, 2008

ASP.NET Data connection performance considerations

“Plan for the performance from the beginning of the development life cycle”.
“Don’t add performance as a post step”
“Design the application for better performance”
The development team must be stressed to focus on the application performance from the beginning not at the end of the life cycle. Some of the recommendations for better data management are

> Open Connections late and close them early.
> Get rid of the connection if it’s not in use.
> Reuse the connection optimally
> Close the connections explicitly
> Use single connection string as different connection string can generate multiple connection pools
> Return what we need from the database

Sunday, April 20, 2008

My Golf experience

My Friend Dr.Raj has been coaching me on Golf fundamentals. I was given instructions to practice easy swing with shoulder movement. On the first day i was practicing to hit nice and easy swing shots covering 80-100 yards. On the second day, Raj gave me the instructions to do putting and chipping. The third day, i was graduated to hit on the 9 hole course with 87-120 yards. I got a par on 110 yards, a birdie on 90 yards and rest of them are boogies. I was so excited when I got birdie on 90 yards. My shots were so powerful that I was able to reach 110 yards with pitching wedge. Since I was hitting 10 yards extra with the regular clubs, Raj advised me to take one club less to reach the target green.

Sunday, April 13, 2008

ASP.NET retain scroll position on Post back

This post is about retaining the scroll position on the ASP.NET page on Post Back. There are few ASP.NET in built features like smartNavigation ,MaintainScrollPosition (2.0 and above) available. But these features have its own drawbacks like tampering the View State, improper page redirects, breaking the css links etc. Here is an approach to retain scroll position in ASP.NET page.

Include a hidden variable in the web page: The hidden variable is added to the web page to save the current position of the window. The hidden variable can be included inside the form tag.



Capture the current scroll position: The javascript injected on the HTML captures the current scroll position. The following document events trigger the function call which will capture the current position.

window.onscroll = saveScroll;
window.onresize = saveScroll;

The script above will trigger the saveScroll method when the window is scrolled or resized. The current position is saved in the hidden variable in the saveScroll method. The definition of saveScroll function is as follows.

function saveScroll()
{
var sScroll;
if (document.documentElement && document.documentElement.scrollTop)
sScroll = document.documentElement.scrollTop;
else if (document.body)
sScroll = document.body.scrollTop;
else
{
sScroll = 0;
}
document.getElementById('__SAVESCROLL').value = sScroll;
}
Restore The Scroll: The scroll position has to be restored when the page post back happens. The following document event triggers the function call which will restore the scroll position.
window.onload = restoreScroll;
The window.onload event will fire after the web page finishes loading. Once the web page finishes loading, the hidden variable where we save the previous scroll position will be available get and restore the scroll back to the same location. The definition of restoreScroll method is given below.

function restoreScroll()
{
var sScroll = document.getElementById('__SAVESCROLL').value;
if (sScroll > 0)
{
if (document.documentElement)
document.documentElement.scrollTop = sScroll;
else if (document.body)
{
if (window.navigator.appName == 'Netscape')
window.scroll(0, sScroll);
else
document.body.scrollTop = sScroll;
}
else
{
window.scroll(0, sScroll);
}
}
}