Home All Groups Group Topic Archive Search About
Author
23 Aug 2006 5:49 PM
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.
--
Regards,
James M

Author
24 Aug 2006 1:41 AM
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.
Author
24 Aug 2006 1:52 AM
James Martin
Unfortunately the label is databound so I can't assign a value.

--
Regards,
James M


Show quoteHide quote
"Steven Cheng[MSFT]" wrote:

> 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.
>
>
Author
24 Aug 2006 4:18 AM
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.
Author
24 Aug 2006 11:46 AM
James Martin
Steven,

It is in the ItemTemplate for a FormView. I will try your suggestion for a
Custom Control. Thanks for your help.
--
Regards,
James M


Show quoteHide quote
"Steven Cheng[MSFT]" wrote:

> 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.
>
>
>
Author
24 Aug 2006 12:42 PM
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.
Author
28 Aug 2006 1:01 PM
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.