user1468537
user1468537

Reputation: 703

asp.net breaking code into separate lines on the aspx page

What's the syntax for the aspx pages if you want to break down really long lines of code into a more readable format.

Example:

 <asp:Label runat="server" ID="lblTest" CommandName="Sort" CommandArgument="Efficiency" ForeColor="White" Text="<img src='images/bluecell.png' /> = 66 - 100 % <br><img src='images/greencell.png' /> = 33 - 66 % <br> <img src='images/ambercell.png' /> = 0 - 33%"> </asp:Label>

into something like:

<asp:Label runat="server" ID="lblTest" CommandName="Sort" CommandArgument="Efficiency"
 ForeColor="White" Text="<img src='images/bluecell.png' /> = 66 - 100 % <br><img
 src='images/greencell.png' /> = 33 - 66 % <br> <img src='images/ambercell.png' /> = 0 - 33%">
 </asp:Label>

Or is it not possible to break up the value of one individual attribute?

Upvotes: 0

Views: 1636

Answers (2)

Dark Hippo
Dark Hippo

Reputation: 1265

Had a quick play with this, and I was surprised to see that just spreading the Text attribute across multiple lines did produce valid markup (as far as I can see).

<asp:Label runat="server" 
           ID="lblTest" 
           CommandName="Sort" 
           CommandArgument="Efficiency" 
           ForeColor="White" 
           Text="<img src='images/bluecell.png' /> = 66 - 100 % <br>
                 <img src='images/greencell.png' /> = 33 - 66 % <br>
                 <img src='images/ambercell.png' /> = 0 - 33%" />

It does kind of screw with the colour formatting in VS, but when it's displayed in the browser it produces:

<span id="ctl00_ContentPlaceHolder1_lblTest" CommandName="Sort" CommandArgument="Efficiency" style="color:White;"><img src='images/bluecell.png' /> = 66 - 100 % <br><img src='images/greencell.png' /> = 33 - 66 % <br><img src='images/ambercell.png' /> = 0 - 33%</span>

So just try putting it on different lines, ignore VS trying to colour code something it doesn't understand and see what you get.

(by the way, use <br /> instead of <br>)

Upvotes: 1

Abdullah Musani
Abdullah Musani

Reputation: 94

You can do this by only pressing CTRL+k+D. Visual studio do the formatting and indenting by itself.

May it helps you.

Upvotes: 3

Related Questions