Nov 24, 2006

Google Analytics open for all!

Google has finally announced that you no longer need an invitation to use their brilliant free web stats program Google Analytics

If you have a website or blog I strongly suggest that you sign up to this service right now!
More Info

Nov 6, 2006

How to make Adobe Reader 7.0 load faster

Whenever I install Adobe’s Acrobat Reader I also uninstall most of the pointless plugins, to speed up its dog-slow startup process.

So here’s what I just did on my machine:

  1. In Edit-Preferences, do the following:
    • General tab: turn off “Automatically save document changes”
    • Internet tab: turn off all three checkboxes
    • Page Display tab: turn on “CoolType”
    • Search tab: turn off “Enable fast find”
    • Startup tab: turn off “Show messages and automatically update”
  2. In View-Toolbars, turn off “Rotate view” and “Search the internet”. Under “Show button labels”, turn them all on so you can figure out what the heck those icons means.
  3. Fire up Windows Explorer and do the following:
    • Navigate to C:\Program Files\Adobe\Acrobat 7.0\Reader\
    • I discovered there's a subdirectory called “Optional” that contains a readme with the following text: "Put unused plug-ins in the optional directory."
    • Move all the .api files from the plug_ins subdirectory to “Optional” subdirectory, except for AcroForm.api (for form-filling) and EScript.api (dependency of AcroForm.api).

What you wanted to actually know what all those plug-ins did so that you can make up your own mind? Move them back again, launch Acrobat Reader, and go to Help-About Adobe Plugins to learn what each plug-in does and what its dependencies are. Oh, and if you speed up Adobe 7.0 by removing some plugins, the update process will have left some subdirectories under C:\Program Files\Adobe\Acrobat 7.0\, so if you’re tidy-minded you can delete those too.

Nov 3, 2006

Use Substitution Control for Dynamic sections of a Cached Page

Ways of Caching an ASP.NET Page in which we are limited to two options


i. Caching the whole page using Output Caching - Not applicable in many realtime scenarios where some sections of the page need to be dynamic ex.- Stock Rates

ii. Caching Usercontrols by Fragment Caching - Difficult to implement since page requires to be breaked into separate usercontrols for enabling/disabling caching.


So, if we had situation where we want the whole Page to be cached and only a particular portion of the page not to be cached, we have to separate the page into usercontrols and then provide caching only for those sections for which we need to cache and leave the dynamic section without caching. The reason is that, if you specify outputcaching for the page, then the whole page, including the controls will be cached for that duration.

Thanks to the Substitution Control to specify a section on an output-cached Web page where you want dynamic content substituted for the control.


The Substitution control offers a simplified solution to partial page caching for pages where the majority of the content is cached. You can output-cache the entire page and then use Substitution controls to specify the parts of the page that are exempt from caching.


The syntax for declaring a substitution control is as follows:-

< asp:substitution id="Substitution1" methodname="Provide Method Name Here" runat="Server">
</asp:substitution>

Let us examine how we can check the functionality of the Substitution control on an output cached page.
In our ASPX Page, first we will declare the Output Caching next to the Page Directive as follows:-

<%@ Outputcache duration="60" varybyparam="none" %>

Where the duration="60" specifies that the page will be cached for 60 seconds.
Then, we declare a label, a substitution control and a button control as follows:-

<asp:substitution id="Substitution1" methodname="GetCurrentDateTime" runat="Server">
</asp:substitution>
Label displaying the Current Date !!!
<asp:label id="lblCurrentDate" runat="Server"> </asp:label>
Substitution control displaying the Current Date !!!
<asp:button id="btnRefresh" text="Check Now !!!" runat="Server">
</asp:button>

Then, in the codebehind, we specify the text for the Label in the Page_load event as follows:-

void Page_Load(object sender, System.EventArgs e)
{
lblCurrentDate.Text = DateTime.Now.ToString();
}

We will set the Current Date Time to the label so that when we refresh the page, we can see whether the time is retained or new time is displayed on the Label.


Next, we have to define the method that is specified to the Substitution control. If we examine the substitution control declaration above, we can see that we have specified as methodname="GetCurrentDateTime".


When the Substitution control executes, it calls a method that returns a string. The string that the method returns is the content to display on the page at the location of the Substitution control.

We define the method "GetCurrentDateTime" in the codebehind as follows:-

public static string GetCurrentDateTime(HttpContext context)
{
return DateTime.Now.ToString();
}

After compiling the application, if we browse the page we fill find that the text below Label and Substitution control is the same i.e. the Current Date and Time.


However, if you refresh the page by clicking the Button, you will find that the time displayed in the Label remains the same, while the time displayed in the Substitution control is changed (the change might be in seconds).


For subsequent requests also, the time would be changing in substitution control while it remains the same in the label, until the duration of "60" seconds expires.
Once it expires then both the label and substitution control would display the updated current time.


Thus we can see that though we have cached the whole page using output caching, the substitution control is dynamic to show the current time.


This is really a great advantage for developers who would like to use Caching for building robust applications while maintaining dynamic sections of their page as well.
There are other ways to achieve this functionality which I would discuss in my next articles.