Controlling whitespace when using server-side evaluation

Last post 12-19-2007 8:35 PM by damieng. 2 replies.

Sort Posts:

  • Controlling whitespace when using server-side evaluation

    12-19-2007, 2:44 PM
    • Member
      444 point Member
    • Dugald
    • Member since 05-07-2007, 2:51 PM
    • Raleigh, NC
    • Posts 85

     Currently, if there is a line of code in a ViewPage, for example:

    <% foreach (Product p in ViewData) { %>
     When evaluated, a blank line is emitted to the resulting HTML. Is there a way to control when/if these blank lines are emitted into the HTML?  I like to have my code formatted with a decent amount of breaks, but the resultant HTML is not what I would like to see.
     
  • Re: Controlling whitespace when using server-side evaluation

    12-19-2007, 4:23 PM
    • Member
      574 point Member
    • abombss
    • Member since 06-27-2006, 4:13 PM
    • Chicago, IL
    • Posts 164

     Nice call, Brail for Monorail has the ability to have <%... -%>  The - before the closing script tag tells Brail to squash the new line.  It makes for some very nice html.

    If we are talking about extending the asp.net compiler for MVC, I would throw this into the mix. 

    Adam Tybor -- abombss.com
    Filed under: ,
  • Re: Controlling whitespace when using server-side evaluation

    12-19-2007, 8:35 PM
    • Member
      38 point Member
    • damieng
    • Member since 06-26-2002, 1:04 PM
    • Guernsey, CI
    • Posts 16

     The trick is placement of the <% %> tags which should be where the HTML & whitespace should stop and not where the code starts...

    e.g. if you wanted all the options on one line but the code over many; 

    <select id="something"><%
    foreach(Product p in ViewData) {
         %><option value="<%=HttpUtility.HtmlAttributeEncode(p.Code)%>"><%=HttpUtility.HtmlEncode(p.Description)%></option><%
    }
    %>

    [)amien 


     

    [)amien
Page 1 of 1 (3 items)