I was trying to display lblName1 and lblName2 only if they have text. Even when i dont have any value for lblName2, the break still has an impact. Can someone please advice me if there is any other way to display
or conditionally display<asp:Label ID="lblName1" runat="server" Visible= "false" ></asp:Label> <br />
<asp:Label ID="lblName2" runat="server" Visible= "false"> </asp:Label>
Tha开发者_Go百科nks in advance..
Give the label a CSS class name and set the margin for that class:
<asp:Label ID="lblName1" CssClass="Testing123" runat="server" Visible= "false" ></asp:Label> <br />
.Testing123{ margin-bottom: 20px; }
If the Label is not rendered then no gap will be created.
You might consider adding a litteral to handle the br and this way play with its visibilty :
<asp:Literal runat=server Id=C_lit_Br><br /></asp:Literal>
with in your codebehind :
if (!lblName2.Visible)
C_lit_Br.Visible=false;
It is a quick patch, but it should work.
It is better to use literal in that case:
In literal text you also write html in it
wrap the labels in p tags:
<p><label1></p>
<p><label2></p>
Going with what you have and ignoring using any code behind changes, you can use some css to provide a break without using a <br />
tag.
By this, I mean if you were to give your <label>
controls a css class, class="labelStyle
.labelStyle{
float: left;
clear: left;
}
Your html produced would look like
<span class="labelStyle">Some Text</span><span class="labelStyle">More Text</span>
If there is no value in the Labels, then your html would contain two empty span tags.
This will move the 2nd label onto the next line. However this may not fit in with the rest of your html, and because you are floating elements, then your overall layout might break.
An example is here http://jsfiddle.net/2v93f/
精彩评论