label overlap during design

J

James Martin

I have several labels in a FormView control on a C# ASP.NET web form. Each
label is bound to a specific field in a datasource. In the template
ItemTemplate I have positioned the labels where they should be. The problem I
have is that when designing the layout in some instances the labels are
overlapping since the text displayed contains the ID of the label. While the
page displays correctly when viewed in a browser it makes for a mess when
designing the form. I am unable to reduce the width of the label to less than
the minimum length required to display the ID when desiging the form. An
example would be a label requiring only enough room to display 3 digits at
runtime has to display the ID, in this case lblMinutesDowntimeData, during
design of the form. This means that whatever label I place to the right of
this label will be placed over the top of it.
 
S

Steven Cheng[MSFT]

Hello James,

Yes, as you have found, the VS 2005 webform designer will display the Label
control's ID in the content area and sometimes long label ID will cause the
label to occupy large design-time space on the design-view.

Actually, this feature is designed for let the developer find and select
the label more convenient when we haven't put anything for the Label's Text
property(or assign an empty string). So if you have assigned any non-empty
value to the label's text, the designer will no longer display the "ID" as
its content.

For your scenario, is your label controls keep empty for there "Text"
property at design-time and only assign value to them at runtime? If this
is the case, you can try assigning the label.Text a single char (a space or
a dot). e.g.


<asp:Label ID="lblFirstOne" runat="server" Text=" "></asp:Label>
<asp:Label ID="lblSecondOne" runat="server" Text="."></asp:Label>


Hope this helps. Please feel free to let me know if there is any other
information you wonder.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Thanks for your quick reply James,

As for the databinding label, are you put it in any template databound
control or just on the top level form?

Since label control can add a initial value in its server tag's inner
content area. You can try add a placeholder char there at design-time. e.g.


<asp:Label ID="lblText" runat="server" Text='<%# Page.ID %>'>£®</asp:Label>

or

<asp:Label ID="lblText" runat="server" Text='<%# Page.ID %>'>#</asp:Label>

If the label is put in template databound control(like repeater, datalist),
it seems the label will always display as "databound" in designer view.

BTW, another possible means(maybe a bit complex) is creating a custom label
control and use ControlDesigner to override its design-time html rendering.
Thus, we can use this custom label control in those place whether we do not
want to let it display ID by default.


Does this helps some?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

James Martin

Steven,

It is in the ItemTemplate for a FormView. I will try your suggestion for a
Custom Control. Thanks for your help.
 
S

Steven Cheng[MSFT]

Hi James,

To create a simple custom Label with a custom desiger, here is a simple
example:

I override the three methods that will return the design-time html of the
webcontrol(display a placeholder char--#)

====================================
[Designer(typeof(SimpleLabelDesigner), typeof(IDesigner))]
[ToolboxData("<{0}:SimpleLabel runat=server></{0}:SimpleLabel>")]
public class SimpleLabel : Label
{

}


public class SimpleLabelDesigner : ControlDesigner
{
public override string GetDesignTimeHtml()
{
return "#";
}

public override string GetDesignTimeHtml(DesignerRegionCollection
regions)
{
return "#";
}

protected override string GetEmptyDesignTimeHtml()
{
return "#";
}

}
====================================

However, I found that for template databound control (Like Gridview,
repeater or FormView), the design-time html is not controled by control
itself , but controled by the template databound control. If you put the
following control item into different template databond
control(ItemTemplate), the design-time text is also different:

<asp:Label ID="CategoryIDLabel1" runat="server" Text='<%#
Eval("CategoryID") %>'>

Anyway, please feel free to let me know if there is any other information
you wonder.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi James,

Any further progress on this issue? If there is anything else we can help,
please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top