Question about the <script runat="server> tag to keep DW from modifying the @page directive for .NET applications


I feel a bit thick, but could someone please give me a little more insight into how this works?:

I'm having the same problems with DW modifying the @page directives for my .NET application, but I don't quite understand how the remedy works, or where exactly the tag goes.

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Jason C. LevineConnect With a Mentor No oneCommented:
Hi tmccrank,

No, each of those was a solution unto itself.  If #1 didn't work, undo it and try #2.  #3 was a solution that works for a similiar DW problem with PHP templates, so I figured it's worth a shot.

I don't normally do ASP.NET at all, so my answers are based on seeing other questions and answers here.  No guarantee that my answers are valid.

Rouchie, have you see this before with DW and ASP and is there a hack for it?  You know this platform way better than I do.
Jason C. LevineNo oneCommented:
Hi tmccrank,

DW allows code in templates that is outside of the HTML tag to be edited despite the template restrictions and the @page directive is being modified because DW is seeing a path there and is trying to rewrite all paths from the Templates directory to wherever.  There are a few things you can try.

1) Add the <script runat="server"></script> around the @page

2) Lock the code in the child pages by changing:

<!-- InstanceBegin template="/Templates/filename.dwt.asp" codeOutsideHTMLIsLocked="false" -->


<!-- InstanceBegin template="/Templates/filename.dwt.asp" codeOutsideHTMLIsLocked="true" -->

3) Chage the paths in the @page to full server paths (this works for PHP include problems in templates).

This isn't my answer; more an opinion.  I was forced to move away from Dreamweaver because if its appalling support for .NET programming.
Microsoft have a free web page editor (downloadable from ASP.NET) that is superb, but lacks the layout design power of Dreamweaver.  I'd advise running this to actually code your pages, then when you've done, switch to Dreamweaver to provide the styling and layout.

Microsoft are actually releasing a new free product that smacks all over DW's functionality for the styling (and still allows the .NET coding).  I'm not sure how this affects their long-running "let's avoid each other's business share" behaviour.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

tmccrankAuthor Commented:
Thanks for your answers.  

jason1178: I think I misunderstood your instructions to mean that each one was a possible solution in itself... so I tried adding just the <script runat="server"> tags around the @page directive.  Needless to say it didn't work, I had to go through and manually change a bunch of stuff again... :-|   So, if I get you right, I need to add the <script> tag as well as adding the <!-- InstanceBegin template="/Templates/filename.dwt.asp" codeOutsideHTMLIsLocked="false" --> bit?  I'm not working with PHP, so #3 shouldn't be much of an issue (I think).

Rouchie: frustrating, isn't it?  Any idea when the new free product is supposed to come out?
RouchieConnect With a Mentor Commented:
I've not seen this happen before, so let's attack it one step at a time.  The first thing in the other post you linked to that doesn't seem totally correct is the way in which the codebehind file is linked to.  The person used this example:


but I would use the ASP.NET application path symbol instead of ".." to give a more secure link (in case the directory location of each one changes):


Try replacing ".." with "~" at the start of any paths.

>> Any idea when the new free product is supposed to come out?

Beta download is available now, although interestingly enough on MS's web site "Free" has now become "Free Trial", so I don't know if they are planning to charge.

>> so I tried adding just the <script runat="server"> tags around the @page directive

No this wouldn't work because the @Page directive contains information to make <script...> work, so <script...> always needs to come after @Page.
I don't really following the solution in the linked post.  Can you post the code of a child page and I'll have an educated guess at where to place the <script...> tags?
tmccrankAuthor Commented:
Rouchie: I agree that the @Page directive shown in the post I linked to looks strange.  Mine hasn't been giving me problems (other than when DW is modifying it), so I don't think that's a problem.  FYI, here is an @Page directive from one of my pages:

<%@ Page Language="vb" ContentType="text/html" CodeBehind="Feedback.aspx.vb" AutoEventWireup="false" Inherits="NurseEducationModules.Feedback" %>

Also, FWIW, it looks like the MS software you're talking about (Expression) is being offered as a 60 day free trial.  Looks interesting though.  I can't install it at the moment as I'm running Office 2007 Beta (a no-no with Expression).

I took out the <script runat="server"> tags.  I copy & pasted "<!-- InstanceBegin template="/Templates/filename.dwt.asp" codeOutsideHTMLIsLocked="true" -->" in the <head> portion of my template html as per Adobe (  After pasting it, two strange things happened:  1) I can no longer edit the tag in DW (it should have NEM.dwt as the filename instead of filename.dwt.asp); and 2) it keeps moving itself *in front* of the <head> tag.

I can freely edit the template file in VS.NET, so giving the tag the proper filename isn't a problem; however, it still stubbornly refuses to move inside the <head> tag.

When I try to apply the template to one of my pages, I'm confronted with this error: " 
tmccrankAuthor Commented:
Sorry... acccidentally posted the last one before finishing...

The error I get is: "There is an error at line 4 of "(my template file path)": Unbalanced InstanceBegin tag.
Jason C. LevineNo oneCommented:
>> "There is an error at line 4 of "(my template file path)": Unbalanced InstanceBegin tag.

Does the receiving page have DW Template markup in it before you apply the template?  That would account for that error.
tmccrankAuthor Commented:
Thanks jason1178.   I hate to say it, but I'm coming up with errors that appear when I try to update pages after modifying the template - that have little to do with my original question.

FWIW, I think that the following from the Adobe website I posted above should help those that are running into a similar problem with having the @Page directive altered:


1       Open the template file.
2       Type (or copy):

<!-- TemplateInfo codeOutsideHTMLIsLocked="true" -->

  into the head of the template file.
3       Save your changes. The change will propagate to the instances. Existing code will be locked and no additional code can be added to the region.


My problem is that most of my .aspx (.NET) pages are not updating.  All of the .html pages are updating fine.  Would anyone mind if I posted the code, or should I start another thread?

Jason C. LevineNo oneCommented:

I posted that at the very beginning.  Solution #2 :)

You may want to close this out and start a new thread.  Get more experts looking at it.  Try posting it in the ASP forums here...
tmccrankAuthor Commented:
Hi jason1178,

I did see that... I was running into problems with it though.  

This is what you posted: <!-- InstanceBegin template="/Templates/filename.dwt.asp" codeOutsideHTMLIsLocked="false" -->

This is what the Adobe site had: <!-- TemplateInfo codeOutsideHTMLIsLocked="true" -->, very similar, but less problematic for some reason.

Anyway, my issue now is that I can't test it because of these other problems I'm running into.  I'll start another thread.

Man, complicated stuff!  :-)
tmccrankAuthor Commented:
jason1178 - thanks for your help... is there a way that I can award you some points for your help up to now?
Jason C. LevineNo oneCommented:
Yes, but you should split the points between myself and Rouchie:

Read the "More than one expert helped..." section.

Thanks Jason.
tmccrankAuthor Commented:
Absolutely right... thanks to both of you.  I'll just split the points as they are now.
All Courses

From novice to tech pro — start learning today.