Friday, April 25, 2008

Web Deployment Projects & Updateable Sites

I am growing very fond of the Web Deployment Project for Visual Studio. I have found it to be an integral piece of my web site; however, I have just ran into a small gotcha which is related to the Allow site to be updated option (Note: This option is not specific to the web deployment project but a part of the ASP.Net compilation model).

One of my web pages is a highly customized printout. I leveraged server side code in the .aspx page to simplify which elements are displayed take the following html fragment for example:

<%if (DisplayAllines)


<div style="float: right">

<asp:Table ID="lines" runat="server" />




{ %>

<div style="float: right">

Grand Total:

<%=Bid.GrandTotal().ToString("C") %>


<%} %>

When you publish your site as updateable, the server side code here is not compiled. I had accidently used the wrong capitlization for an abbreviation in simillar code, and while it compiled without a problem, it would not run.

If you turn off updateable site feature, and run a build, Visual Studio does catch the syntax error.

On a side note I wish Microsoft would better support server side scripting tags. I use these a lot in some of the javascript for my user controls (Particulary if the control will exist multiple times on the same page), as a way to quickly and easily distinguish btw javascript objects. For example:

var <%=this._gridAssets.ClientID %>GridSelection;

var isError=false;

function onLoad<%=this._gridAssets.ClientID %>Grid(sender,eventArgs)


    <%if(!ReadOnly){ %>

    <%=this._gridAssets.ClientID %>GridSelection=new selectedGrid(sender,4,null);

    <%} %>


In this example here, I have a custom javascript object which is associated with a grid in this user control. I use the ClientId of the grid to act as a namespace. This same trick is also handy if you need to access server side controls from javascript and those controls will exist in a naming container.

When you do this you will be flooded with syntax warnings as the parser is trying to treat the script directives as client side script. Intellisense almost never works here either (It will work outside of a <script> tag).


No comments: