Archive for the 'ASP.NET' Category

FREE MSDN Magazine

If you are a Microsoft programming fans, it is a good stuff for you. Hurry up, get the MSN magazine for free @ here.

Today, they just released June edition

Highlight for this month

Tagged Under ( , , , )

How to Sleep in Office?

1. Get this print out

Read the rest of this entry »

Tagged Under ( , )

Sys.WebForms.PageRequestManagerParserErrorException @ MS Ajax

Spending a weeks to troubleshoot the "Sys.WebForms.PageRequestManagerParserErrorException" error in my company’s project.


Finally I found the workaround for it. Very easy, just disable the enableEventValidation on the ASPX page containing the UpdatePanel.

If this workaround doesn’t work for you, you should probably look @ Eilon Lipton’s Blog. Here is some of his findings:

Why do I keeping getting a PageRequestManagerParserErrorException?

Read the rest of this entry »

Tagged Under ( , , , )

MS AJAX : Update Panel only postback once

Recently, I was assigned to migrate Magic Ajax to MS Ajax. I found out that MS Ajax doesn’t support the following code that tied to the onSubmit attribute on the server form:

ServerForm.Attributes.Add("onSubmit", "if (this.submitted) return false; this.submitted = true; return true");

Basically, this javascript used to prevent Users from Submitting a Form Twice. Indirectly, it only allow asp:UpdatePanel to post back once. The subsequent post back is blocked.

The workaround is remove the attached javascript and it will works fine. However, it break the rule on preventing multiple form submision.

I proposed two better approaches to replace the workaround.

1. Disabling a Button When Clicked (by

Many websites prevent a user from submitting a form more than once by disabling the submit button upon being clicked. Along with disabling the submit button, sites typically change the button’s text from its initial value (such as "Submit") to some other value indicating than action has taken place (like "Submitted"). Changing the text and disabling the button can be accomplished using a couple lines of JavaScript in the button’s client-side onclick event handler:

 Here is the live demo.

2. "Freezing" the Page On Form Submission (by

Nowadays, many websites freeze the screen when the form is submitted. It is  to prevent double form submissions. Specifically, the screen is frozen by placing a full screen, absolutely positioned element above all other elements on the page (specifically a <div> element). This covers up the content beneath the element and prevents the user from interacting with the form elements.

This technique is very common for Rich application development especially Ajax-support websites. Once you freeze up the page, you can do a lot of background processing in the  asynchronization way.

 Here is the live demo.

Tagged Under ( )

HTTP Compression in ASP.NET 2.0

These two days, I was looking for a way to enable HTTP Compression in ASP.NET 2.0 for my project -

Last time, I tried to enable to http compression in IIS6 for ASP.NET 1.1. Here is a good guide to follow - IIS Compression in IIS6.0. Currently, I am using a shared web hosting with no access to the server configuration. So, I have to find a way to enable the compression without touching the IIS settings.

At first I tried the Mads Kristensen’s way of compression.

The new System.IO.Compression namespace in .NET 2.0 makes it easy to implement HTTP compression without having to touch IIS. The best thing about it is that you no longer need any third party compression components, it’s all build directly into .NET Framework.

There are different ways to implement the compression but I think an HttpModule is the right choice for this feature. Let’s create one and call it CompressionModule.

The CompressionModule must adhere to the following rules:

  • Support both GZip and Deflate compression
  • Only compress if the browser supports it
  • Simplest possible implementation

These rules are important to make sure that the compression will run smoothly in every situation.


Download the CompressionModule.cs file below and add it to the App_Code folder in the root of your website. Then add these lines to the web.config’s <system.web> section.

    <add type="CompressionModule" name="CompressionModule" />

That’s all you have to do to enable HTTP compression on an ASP.NET 2.0 website.

Download (0,75 KB)

Unfortunately, the compression is activated but all the javascript validation doesn’t work as expected. It caused by the compression on the WebResource.axd.

The .NET 2.0 framework changed the way clientside JavaScript is delivered to the browser. Previously, ASP.NET 1.1 used the aspnet_client directory whereas now 2.0 uses WebResource.axd.

The only solution to solve this problem is exclude the compression on WebResource.axd. But, I couldn’t find a way to do it.

Then, I tried a another famous Http Compression engine for ASP.NET 2.0 - Blowery.

Blowery - This is a pretty simple recompile of the version 6 source, targetting the 2.0 version of the .NET Framework. It now uses the built-in deflate and gzip streams found in System.IO.Compression instead of #ziplib. I consider this a beta release; please test it thoroughly before releasing it onto any production systems. [Binary Only, Source Only]

Here is the implementation plan:

  1. Download the Binary DLL.
  2. Extract the package and copy the extracted files into the bin folder of your .Net application.
  3. Modify your Web.config
    1. Add to the configSections
      <sectionGroup name="blowery.web">
       <section name="httpCompress" type="blowery.Web.HttpCompress.SectionHandler, blowery.Web.HttpCompress"/>
    2. Add to the httpModules section inside system.web (if httpModules section does not exist, create it)
      <add name="CompressionModule" type="blowery.Web.HttpCompress.HttpModule, blowery.web.HttpCompress"/>
      </ httpModules>
    3. Add to the configuration section
      <httpCompress preferredAlgorithm="deflate" compressionLevel="high">
          <add type="image/jpeg"/>
          <add type="image/gif"/>

However, it still giving the same problem on the javascript validation. Luckily, I managed to find Ross Hawkins’s Troubleshooting WebResource.axd. He suggested to download the source code from Browely and change a small code in Line 85, httpCompress.cs:


string realPath = app.Request.Path.Remove(0, app.Request.ApplicationPath.Length+1);


string realPath = Path.GetFileName(app.Request.Path);

Then, I recompile the library and add it into my project. Finally, it works.

Here is the statictic of enabling http compression:


Thanks to Port80 - Http compression Checker

Now, my page load 4.5 times faster. The compression rate is 79%.

Tagged Under ( )