Response.Redirect and Server.Transfer Demystified

I still remember the old days when I first learned ASP.NET 1.0, I used to search, like other newcomers, for the differences between Response.Redirect and the Server.Transfer. I found answers such as Server.Transfer had been kept in ASP.NET for backward compatibility with ASP so the recommendation was to use Response.Redirect or that I should be using the Server.Transfer for better performance!

The truth is every method has a completely different and important use.

Response.Redirect : When you call this method, ASP.NET will issue HTTP headers that will instruct the browser for the new page tonavigate to and will stop processing any further ASP.NET instruction. The following code:

Read More

How to HTTP Post in .NET and handle the 500 errors

If you google you will find a lot of posts that will tell you how to HTTP post (some call it HTML post) in .NET. However, they all fail, or at least the ones I found, to tell you how to handle the returned 500 errors and retrieve the message behind it.

I have been posting to a service and getting the “500 Internal Server Error” which doesn’t tell much! I had done some research to get the real error behind it. Here is my code snippet in C#:

Read More

Check Validator: An ASP.NET Validator Control

Check Validator used with checkbox

While some developers assume that the classical ASP.NET validators support check boxes and radio buttons, this isn’t the case! There is a logical explanation for this; there is nothing much to check, the checkbox can only be checked or unchecked so what do you want to validate?

In some cases you might want to display an error if a check box or a radio button is unchecked, e.g. terms and conditions check box, if so, then this is the right validator for you. Read on if you are interested in the bits and pieces of how the control works or skip to the “Using The Validator” section if you are just interested in using it.

Read More

Session Keep-Alive Web Control

Visual Studio project structure overview

Session expiration in ASP.NET is a nasty problem. Imagine yourself filling a long form, hitting submit then boom you get the login page! That happened to me before and probably happened to you.

This problem doesn’t have an out-of-box solution in ASP.NET and there are different appraoches to solve it.

  1. Increasing the session time out. Probably you are aware of the cons of this problem which are mainly consuming more server resources.
  2. Having an image or an iframe that refreshes regularly and requests the server. This approach is a per page approach and you can select the pages to implement it on.

Personally, I’ve been using the second approach for a long time and didn’t have any problem with it. However, I made it more reusable, not to mention “cleaner”, by making it a web control.

If you are just interested in using the control then you can skip to the last section “Using the Control.”

Read More