Aug 26, 2011

Server.Transfer vs. Response.Redirect

ping from 

If you read a lot of industry magazines and ASP.NET code samples, you may find that, although the majority use Response.Redirect to send the user to another page, some seem to prefer the rather mysterious-sounding Server.Transfer. So, what's the difference?

Well, Response.Redirect simply sends a message down to the browser, telling it to move to another page. So, you may run code like:




to send the user to another page.

Server.Transfer is similar in that it sends the user to another page with a statement such asServer.Transfer("WebForm2.aspx"). However, the statement has a number of distinct advantages and disadvantages.

Firstly, transferring to another page using Server.Transfer conserves server resources. Instead of telling the browser to redirect, it simply changes the "focus" on the Web server and transfers the request. This means you don't get quite as many HTTP requests coming through, which therefore eases the pressure on your Web server and makes your applications run faster.

But watch out: because the "transfer" process can work on only those sites running on the server, you can't use Server.Transfer to send the user to an external site. Only Response.Redirect can do that.

Secondly, Server.Transfer maintains the original URL in the browser. This can really help streamline data entry techniques, although it may make for confusion when debugging.

That's not all: The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.

For example, if your WebForm1.aspx has a TextBox control called TextBox1 and you transferred to WebForm2.aspx with the preserveForm parameter set to True, you'd be able to retrieve the value of the original page TextBox control by referencing Request.Form("TextBox1").

This technique is great for wizard-style input forms split over multiple pages. But there's another thing you'll want to watch out for when using the preserveForm parameter. ASP.NET has a bug whereby, in certain situations, an error will occur when attempting to transfer the form and query string values. You'll find this documented at;en-us;Q316920.

The unofficial solution is to set the enableViewStateMac property to True on the page you'll be transferring to, then set it back to False. This records that you want a definitive False value for this property and resolves the bug.

So, in brief: Response.Redirect simply tells the browser to visit another page. Server.Transfer helps reduce server requests, keeps the URL the same and, with a little bug-bashing, allows you to transfer the query string and form variables.

Top Tip: Don't confuse Server.Transfer with Server.Execute, which executes the page and returns the results. It was useful in the past, but, with ASP.NET, it's been replaced with fresher methods of development. Ignore it.

About the Author

Karl Moore (MCSD, MVP) is an experience author living in Yorkshire, England. He is author of numerous technology books, including the new Ultimate VB .NET and ASP.NET Code Book, plus regularly features at industry conferences and on BBC radio. Moore also runs his own creative consultancy, White Cliff Computing Ltd. Visit his official Web site at

Improve Team Foundation System Compare/Merge function

We (.NET developer) probably agrees that the built-in compare/merge tool of TFS is not good enough.

OK I know we have better solutions to do code compare/merge  (for e.g: WinMerge, Beyond Compare…etc).
Good news: we can use these software as custom tools in TFS.


Step 1: In Visual Studio, click Tools –> Options

Step 2: Go to Source Control –> Visual Studio Team Foundation Server

Step 3: Click Configure User Tools,

Step 4: Click Add/Remove/Modify to setup your custom tools. Configure the path and arguments as you want.

Enjoy ! Happy code comparing

Aug 23, 2011

Tidy up a messy XML

Notepad++ ( download here) can help a lot in re-format or tidy up an messy XML

From Notepad++ menu: TextFX -> HTML Tidy -> Tidy: Reindent XML

This feature however wraps XMLs and that makes it look 'unclean'. To have no wrap,

  • open C:\Program Files\Notepad++\plugins\Config\tidy\TIDYCFG.INI,
  • find the entry [Tidy: Reindent XML] and add wrap:0 so that it looks like this:
[Tidy: Reindent XML] 
input-xml: yes
Enjoy XML everyone !

Aug 21, 2011

Dynamic calculation of field values in TFS 2010

If you are here because you might want to ask TFS 2010 to auto-update some fields (such as remaining work vs. completed work), then you’re lucky because of there is a TFS Aggregator plugin:

Download link : here 

This server-side plugin let TFS does such things. Some of its nice features:

  • Update the state of a Bug, PBI (or any parent) to "In Progress" when a child gets moved to "In Progress"
  • Update the state of a Bug, PBI (or any parent) to "Done" when all children get moved to "Done" or "Removed"
  • Update the "Work Remaining" on a Bug, PBI, etc with the sum of all the Task's "Work Remaining".
  • Update the "Work Remaining" on a Sprint with the sum of all the "Work Remaining" of its grandchildren (i.e. tasks of the PBIs and Bugs in the Sprint).
  • Sum up totals on a single work item (ie Dev Estimate + Test Estimate = Total Estimate)

OK that’s it. Please visit the site for more info.

Happily working on Sunday.

Aug 17, 2011

Favorite quotes–Quote of the day

I know this is not a technical blog – but I found it is encouraging to keep a collection of my favorite quotes and update it whenever I found a good one.

Today’s quote come from my build team:

“A true hero need not speak. The world will speak for him when he is gone”

Aug 15, 2011

Visual Studio 2005/2008: “Error Creating Control” while working with Telerik Controls

Ping back from :

I’ve run into this error before and last night it reared its ugly head again. You’ll find it from time to time when switching to Design View in Visual Studio to work with custom server controls. The bug is in Service Pack 1 of VS and can be quite annoying.

1 - Error Creating Control Exceptions

It has been submitted to Microsoft and they claim to be working on a solution which will “fix it in subsequent releases” of Visual Studio. Unfortunately, developers (like me) don’t want their productivity to suffer while we all wait for a fix from Microsoft. So here are a couple of steps you can take to try to resolve this issue yourself:

Solution 1. Close and restart Visual Studio. Some developers claim this solved the problem for them. I cannot confirm that this works because it did not solve the problem for me, but it’s certainly worth a try since it’s quick and does not require you to modify your system in any way.

Solution 2. Delete all project assemblies from your ProjectAssemblies directory.

  • Close Visual Studio
  • Navigate to ProjectAssemblies directory
    • C:\Users\[username]\AppData\Local\Microsoft\VisualStudio\9.0\ProjectAssemblies(Windows Vista)
    • C:\Documents and Settings\[username]\Local Settings\Application Data\Microsoft\VisualStudio\9.0\ProjectAssemblies (Windows XP)
  • Remove all subdirectories
  • Restart Visual Studio

2 - ProjectAssemblies Folder

The second solution did the trick for me. Hopefully one of the above solutions worked for you. If you have run into this bug and found an alternate solution, please let me know and I’ll make sure it gets added to the list.

Aug 11, 2011

Slow connection when connecting to Team Foundation Server from Visual Studio 2010

At a client we were testing our newest line of development machines. After installing Visual Studio 2010 we noticed that the performance was VERY slow when connecting to Team Foundation Server (2010). Performing a get latest of a large solution took several hours(!).

Some investigation showed that it does not appear to be a TFS issue per se but rather something lower in the .NET Framework stack, having to do with automatic proxy discovery through the WPAD protocol.

You can work around the issue by turning off proxy autodiscovery on a per-application basis by using a .exe.config setting.

The .exe.config for Visual Studio is %VSINSTALLDIR%\Common7\IDE\devenv.exe.config and it already contains a section in the .exe.config for System.Net. After adding the defaultProxy element, that section would look like this:

 1: <>
2: <defaultProxy enabled="false" />
3: <settings>
4: <ipv6 enabled="true"/>
5: </settings>
6: </>

Aug 4, 2011

Render your Windows font differently – be like Mac

Have you ever feel envious with Mac OS user because of the way Mac OS renders font ?OK, I admitted I did. But no more – with the help of these things:

  • GDI++ [download]
  • Lucida Grande font [download]
  • Installation:
    - Download these 2 files above.
    - Extract the GDI++ into your Program menu folder, then put a shortcut of Gditray.exe into Startup folder
    - Extract and copy the 2 Lucida Grande fonts into C:\Windows\Fonts
    - Execute the .reg file

    After that, you will see GDI++ icon in the task bar. Click Use preferences –> Bold / Medium / Light.
    Click Enable



    This is what looks like with GDI enabled:image

    And GDI disabled:image