Configuring Dreamweaver MX to recognise ASCX files
Some people may have problems with Dreamweaver MX not properly recognising ASPX and ASCX files when using the ASP.NET Server Model. By default, MX is fairly rigid in the way that it recognises C# or VB.NET pages. In fact, MX will only recognise ASP.NET C# pages that contain:
<%@ Page Language="C#"%>
Pages that contain:
<%@ Page CodeBehind="admin_login.aspx.cs" Language="c#" AutoEventWireup="false" Inherits="CmsDotNet.admin_login" %>
or:
<%@ Control Language="C#"%>
won't be recognised as ASP.NET C# pages. Fortunately, this can be overcome by manually editing certain files in the Configuration folder. Locate the following folder:
C:\Program Files\Macromedia\Dreamweaver MX\Configuration\ServerModels
and open up ASP.NET_Csharp.htm in a text editor. Look at line 352, which will contain the following code:
function canRecognizeDocument(dom)
{
var retVal = (-1);
var langRE = /@\s*page\s*language\s*=\s*(\"|\')?c#(\"|\')?/i;
var oHTML = dom.documentElement.outerHTML;
if (oHTML.search(langRE) > (-1))
{
retVal = 1;
}
if(retVal == (-1))
{
// There isn't an @ page language directive on the page.
// Look for a server-side script language tag.
var scriptTags = dom.getElementsByTagName("script")
for(var i=0; i < scriptTags.length; i++)
{
// Check if it's a server side script tag.
if(scriptTags[i].getAttribute("runat") && scriptTags[i].getAttribute('language')){
// Check if it's VB.
if(scriptTags[i].getAttribute('language').toLowerCase() == "c#")
{
retVal = 1;
// We only care about the first one. Exit the loop.
break;
}
}
}
}
return retVal;
}
Now, you can see that the search pattern is fairly rigid, in that it is specifically looking for <%@ Page Language="C#"%>. So, you could alter the search pattern to be more forgiving. Or (this is what I did), change the line:
return retVal;
to:
return 1;
So that MX will recognise ASPX and ASCX files as ASP.NET C# pages, no matter what they contain. The same logic should hold true for VB.NET pages. Locate the file ASP.NET_VB.htm and look at line 372.
Note: Please use this methodology at your own risk. A Macromedia engineer has remarked:
"Always returning 1 from this function may cause arbitrary results. Let me provide some more detail on this function.
The purpose of this function is to determine the Server Model when 2 Server Models share the same file extension, such as ASP.Net C# and ASP.Net VB share .ascx and .aspx. This function gets called for both Server Models and the one that returns the highest number wins!
So, the problem is if you update *both* of these Server Models to always return 1 (one or the other is OK). If both functions return >= 0, then the "winner" is arbitrary (depending on the order in which the functions are called).
Take a look at the same function for the ASP JavaScript and ASP VBScript functions. In the DW MX 6.1 update, I made these so that the functions return 1 if the file is recognized, 0 if this is the current server model, otherwise -1. This causes all Server Models the ability to "claim" the file, and then it default to current Server Model if the file is unclaimed."

