Friday, January 11, 2008

How do I dynamically add CSS file for ASP.NET ASPX page?

Normally, in our ASP.NET applications we use CSS in Master Pages. Then it will automatically inherit to child pages. But there is an option in ASP.NET to put page specific CSS file and it will swap the master page CSS inheritance.

To implement this we programmatically access the HTML link element under header tag in Page_Init.

FAQ00011

Labels: ,

Wednesday, January 2, 2008

How to detect the connection status among server and client in my ASP.NET application?

With our ASP.NET application, sometimes we may have to process time consuming queries like database transaction, payment gateway integration, time out,  etc... In such situations we have to check the client connection is still alive or not. Coz there is a gap between client request time and server response time.

So, we better to check the client connection status after running complex / time consuming process. Otherwise, server unnecessarily keeps the client’s response and it affects to the server performances.
With ASP.NET you can do it simply like below.

FAQ00002 
FYI: IsClientConnected is a read only property. If IsClientConnected is true, that means client has live connection with the server. If IsClientConnected is false then you can release the server by ending the client response.

Source code: IsClientConnected.zip

Labels: ,

Tuesday, January 1, 2008

How to track the last modified date /time of ASPX page?

One of our customer may ask “I want to see the last modified date or time of my web site. Just show it around the footer so somewhere”. Because, then customer can see the last modernize date/time of web site’s physical files. With ASP.NET, you can archive this with few lines of code.

FAQ00001

You can place above code inside the ASP.NET master page or ASP.NET web user control. Then you can catch the last modified date time of all ASPX pages from single location.

FYI: Above code doesn’t support for non ASPX pages or dynamic ASPX pages (like URL rewriting). So in that case you will have to have added way to track it. Like storing it in the database table or XML file.

Download source code : LastModifiedDateTime.zip

Labels: ,