Friday, February 18, 2011

Client ID problem when moving from .NET framework 3.5 to 4.0

HI guys,
ASP .NET automatically assigns a unique client ID to each and every server side control to make them distinguishable irrespective of the fact that whether 'id' attribute is applied to that control or not. This would be used by various client side operations like JavaScript functions etc.. Now recently we migrated our project from framework from 3.5 to 4.0. And after that I noticed that all the controls that were used in previous framework with prefix like ctl00.. became invalid. Then I figured that the mechanism through which ASP .NET 4.0 assigns the clientID is different from earlier versions. It uses a much cleaner approach like that of simple HTML controls in assigning clientId i.e instead of ctl00Master_XYZ it will use only XYZ as clientd Id.

What if we have used hardcoded autogenerated clientID in javascript functions.
First thing, as good coding convention we should not use the hardcoding of dynamic entity like clientId. You should use this way: <%= Control.ClientID %>'. Now if in any case you have used this thing and owe this 'Technical Debt', then other way is change the clientID Mode. clientId Mode can be changed at control level, Page level or at application level.Using this syntax:

<asp:Label ID="Label1" runat="server" ClientIDMode="[Mode Type]" />

Here set the Mode Type to 'legacy' or 'AutoId'.
It's done!!!
Other Mode types supported are :
Inherit
Static
Predictable


More info on these at
http://weblogs.asp.net/asptest/archive/2009/01/06/asp-net-4-0-clientid-overview.aspx

Wednesday, February 16, 2011

Special care while Migrating an MVC application from IIS6 to IIS7

Hi,
I had a MVC based application that was earlier hosted on IIS 6. Now IIS 6 doesn't support extensionless URL routes by default, so we need to add some extension to the controller name in the default route defined like {ControllerName}.aspx\{Action method}\{Id} in IIS6. Also we if we wanted to go for some other extensions like .mvc etc. then we needed to map it using techniques like wildcard mappngs etc.
Now when we have migrated to IIS7, then extensionless URLs are supported which means URLs can be there which don't have any corresponding physical location.
So when you are migrating your MVC application to IIS7 then make sure the default route define in Globla.asax don't have any extension defined with controller like {controller}.aspx\{action method}\{Id} and change it to \clean URL route {Controller}\{Action Method}\{ID(optional)}.
Second thing you should keep in mind that the pipeline mode of AppPool of the website should be set to Integrated from classic.
That's all now your website is ready to be hosted on IIS7.



Friday, February 11, 2011

IE8 Bug: Jumping Scrollbars

Here is the new bug that is very popular in IE8 explorer. This is often termed as Jumping Scrollbar. The problem  occurs when text is appended at the end of text area then the scrollbar automatically bounces to the top. This is really annoying when user is in middle of typing something. Now several patches are their on web to resolve this issue. This problem occurs when the width of the text area is given in  percentage terms in CSS. The simplest solution to this problem is provide the width of the text  area in in absolute terms instead of percentage terms, like 750 px. Hope Microsoft will resolve this issue soon.