473,377 Members | 1,119 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,377 software developers and data experts.

Span vs. DIV for asp:Label Control

Hello All--

I have a number of <asp:Label CssClass="someclass">Text</asp:Labelcontrols
on my page. I would like them to be shown as
<div class="someclass">Text</div>
rather than
<span class="someclass">Text</span>

When it uses a span, it doesn't seem to use all the class definitions,
particularly for margins and positioning.

I realize I can surround my <asp:Labelcontrols with the <divelements,
but that seems to make the <asp:Labelcontrol unneccessary, doesn't it?

Thanks,
pagates
Sep 19 '06 #1
4 6598
Perhaps the most simple approach would be to change the Label control
would to inherit from it and override the value of the TagKey.

Here is some VB.NET code.

Imports System.Web.UI
Imports System.Web.UI.WebControls

<ToolboxData("<{0}:DivLabel runat=server></{0}:DivLabel>")_
Public Class DivLabel
Inherits Label

Protected Overrides ReadOnly Property TagKey() As
System.Web.UI.HtmlTextWriterTag
Get
Return HtmlTextWriterTag.Div
End Get
End Property

End Class
Brennan Stehling
http://brennan.offwhite.net/blog/
pagates wrote:
Hello All--

I have a number of <asp:Label CssClass="someclass">Text</asp:Labelcontrols
on my page. I would like them to be shown as
<div class="someclass">Text</div>
rather than
<span class="someclass">Text</span>

When it uses a span, it doesn't seem to use all the class definitions,
particularly for margins and positioning.

I realize I can surround my <asp:Labelcontrols with the <divelements,
but that seems to make the <asp:Labelcontrol unneccessary, doesn't it?

Thanks,
pagates
Sep 19 '06 #2
the difference between a span and div is the default display style. a div
defaults to block and a span to inline. if you want you labels to be block
style, just set the style

..someclass { display:block; }
-- bruce (sqlwork.com)
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
Hello All--

I have a number of <asp:Label CssClass="someclass">Text</asp:Label>
controls
on my page. I would like them to be shown as
<div class="someclass">Text</div>
rather than
<span class="someclass">Text</span>

When it uses a span, it doesn't seem to use all the class definitions,
particularly for margins and positioning.

I realize I can surround my <asp:Labelcontrols with the <divelements,
but that seems to make the <asp:Labelcontrol unneccessary, doesn't it?

Thanks,
pagates

Sep 19 '06 #3
If you would like to use divs, why not to go ahead and just do it?

<div class="someclass" runat="server" id="myDiv">Text</div>

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
Hello All--

I have a number of <asp:Label CssClass="someclass">Text</asp:Label>
controls
on my page. I would like them to be shown as
<div class="someclass">Text</div>
rather than
<span class="someclass">Text</span>

When it uses a span, it doesn't seem to use all the class definitions,
particularly for margins and positioning.

I realize I can surround my <asp:Labelcontrols with the <divelements,
but that seems to make the <asp:Labelcontrol unneccessary, doesn't it?

Thanks,
pagates

Sep 20 '06 #4
A Label allows you to set many properties for the Font and other
control settings which is helpful at design-time. And you do not want
to simply set the span to use "display: block" in the CSS because there
is a bug in IE6 which does not truly make that span act as a block
level element. You will want to ensure that it does start as a block.

Doing so will save you from a good deal of trouble.

Brennan Stehling
http://brennan.offwhite.net/blog/
Eliyahu Goldin wrote:
If you would like to use divs, why not to go ahead and just do it?

<div class="someclass" runat="server" id="myDiv">Text</div>

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
Hello All--

I have a number of <asp:Label CssClass="someclass">Text</asp:Label>
controls
on my page. I would like them to be shown as
<div class="someclass">Text</div>
rather than
<span class="someclass">Text</span>

When it uses a span, it doesn't seem to use all the class definitions,
particularly for margins and positioning.

I realize I can surround my <asp:Labelcontrols with the <divelements,
but that seems to make the <asp:Labelcontrol unneccessary, doesn't it?

Thanks,
pagates
Sep 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: moondaddy | last post by:
I want to use a asp Label control (or a <div runat=server> element) in a template column of a datagrid. In the code behind in the grid's ItemDataBound event I need to dynamically set the innerHTML...
2
by: John Holmes | last post by:
I would like to turn on a label control in javascript with the onfocus event of another control by setting the Visible property to true. When I try and reference this label control it says...
4
by: Jeronimo Bertran | last post by:
I am currently using databing to show on an asp:label the result of appending two database fields in the following way: <asp:label id=textAcknowledgedBy runat="server" Text='<%# DataBinder.Eval...
2
by: Shapper | last post by:
Hello, I am creating a contact form in ASP.NET and I need to access the labels on Page_Load on my aspx.vb file. The other elements such as input box and text box don't need to be accessible....
1
by: nospamjac | last post by:
Hi, Is there a way to update the text of an asp:label on a webform without refreshing the entire page? What is called by button clicks and other events that refresh a webform control? See the...
2
by: footballhead | last post by:
I do some design work on a website that up until to now has been limited to defining CSS and HTML elements. Excuse me if I am using incorrect terminology, I am just starting out in this. I would...
4
by: Guy Noir | last post by:
So, I have a table that I only want to appear after some event has fired. Using the asp:table control and the Visible property, this is a piece of cake. The problem is that when I try and drop a...
1
by: Steve Hershoff | last post by:
I'm using VS 2003, and need to extract the text from an asp label in my code-behind file. The label is part of a DataList's ItemTemplate. I've noticed that in my ascx file (we're using User...
0
by: Dhananjay | last post by:
hi all i have a problem on populating a message on asp:label server control.I am able to insert records into the table.but it is not populating any message like "Records entered successfully"....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.