CMXtraneous: ASP.NET

Right on the edge of useful

DreamweaverCtrls problem with ASP.NET ver 2.0

Posted Friday, June 16, 2006 2:35:49 PM by Heidi Bautista

Heidi Bautista

If you've just upgraded from ASP.NET ver 1.1 to ver 2.0 and discovered that existing pages with editable DataGrids no longer work, you're not crazy. There really is a problem with DreamweaverCtrls.

I've reported the problem to Adobe (Macromedia - Feature Request/Bug Report Form) but no reply just yet. I'll update this post when I hear back.

Problem Description

ASP.NET pages with an editable DataGrid do not update the database. There's no error message. The only indication is that when the page redisplays the DataGrid, it still has the old data.

Why the problem exists

ASP.NET automatically creates unique ID's for controls. For example, the 1.1 version of the .NET Framework, the ID looks like this:

DataGrid1:_ctl11:_ctl0

For ver 2.0, Microsoft changed the naming scheme used to generate unique IDs. In ver 2.0 that same control now looks like this:

DataGrid1$ctl11$ctl00

The problem is that DreamweaverCtrls relies on the naming scheme used by ver 1.1 of the .NET Framework. The code looks for the colon character when it's figuring how whether or not the editable DataGrid uses links or buttons for the edit/update/cancel functions. Since the colon doesn't exist in the ver 2.0 unique IDs, the DataGrid is not updated.

The fix

The solution isn't too bad. Only two lines of code in the source file for DreamweaverCtrls have to be modified. The downside to the solution presented here is that once modified, that version of DreamweaverCtrls will only work for ver 2.0. Not a big problem, granted, but something to keep in mind should you decide to implement this fix for your own sites.

Here are the changes that need to be made to the cs file.

Line 2018 --

current code:
int index = eventTarget.IndexOf(":"); 
changed code:
int index = eventTarget.IndexOf("$");

Line 2054 --

current code:
int strIndex = name.IndexOf(":_ctl"); 
changed code:
int strIndex = name.IndexOf("$ctl");

Be sure to make a copy of DreamweaverCtrls.cs before modifying it.

If you installed Dreamweaver in the default location, you'll find the source file for DreamweaverCtrls here:
C:\Program Files\Macromedia\Dreamweaver 8\Configuration\ServerBehaviors\Shared\ASP.Net\Scripts\Source\DreamweaverCtrls.cs

That folder has a bat file to assist with compilation of the C# source. For more information about compiling, see Demystifying .NET Compilers.

Category tags: ASP.NET, Dreamweaver

The good, the bad, and the ugly of C# coding standards

Posted Wednesday, August 18, 2004 12:34:14 PM by Heidi Bautista

Heidi Bautista

Lance Hunt has compiled an impressive set of guidelines for C# coders. Check out his blog and download the pdf for yourself. If you're an old hand at C# coding, you may find some newly preferred standards (like using the as operator instead of direct casting, top of page 12 in the pdf) and if you're a newbie, this is a great place to learn.

Category tags: ASP.NET