65.9K
CodeProject is changing. Read more.
Home

Syntax Change When Building Controls Dynamically in ASP.NET 2.0

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.56/5 (5 votes)

Apr 13, 2006

1 min read

viewsIcon

28794

From ASP.NET 1.x to ASP.NET 2.0 there has been a fundamental syntax change that applies to building server-side controls dynamically.

Introduction

This tiny snippet will attempt to save developers that are porting ASP.NET 1.1 code to ASP.NET 2.0 code. Especially if controls are being built dynamically.

Using the code

The code posted here should replace any legacy ASP.NET code when converting to ASP.NET 2.0 if you are building server-side controls dynamically. It can even be a find and replace but not doing it will cause those controls to not pick up the correct values out of them.

Below is how I retrieved a value from an ASP.NET server control that was built on the fly or dynamically using VB.NET 2003.

Request.Form(me.ClientID & ":controlname")

The above code snippet will not work in Visual Studio 2005. There is no error thrown but the value property of the control returns nothing when there is a valid value available. This makes this little issue hard to catch without unit tests. Below I have included the same line of code as before but with one fundamental difference. The ":" gets replaced by "$".

Request.Form(me.ClientID & "$controlname")

This fixes the issue for ASP.NET 2.0. I did not see any documentation on this so I hope this is useful to someone.