To automatically handle Web controls that have long string display

Source: Internet
Author: User
web| Control | display | string

We often need to display a paragraph on a line of text, and because of the uncertainty of Web page width, we arbitrarily adjust its width, usually make text to support the page or fold into many lines. By using CSS, we can limit the width to one line and hide the extra characters. For convenience, make a small Web control to use.
Using System;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.ComponentModel;

Namespace Cnblogs.birdshome.WebControls
{
/**////<summary>
Summary description for AutoLabel.
</summary>
[Defaultproperty ("Text"),
ToolBoxData ("<{0}:autolabel runat=server></{0}:autolabel>")]
public class AutoLabel:System.Web.UI.WebControls.Label
{
protected override void CreateChildControls ()
{
Base. CreateChildControls ();
This. Width = unit.percentage (100);
This. attributes["onmouseover"] =
"If" (This.clientwidth < this.scrollwidth) this.title = This.innertext; else this.title = '; ';
This. attributes.cssstyle["white-space"] = "nowrap";
This. attributes.cssstyle["Overflow"] = "hidden";
This. attributes.cssstyle["Text-overflow"] = "ellipsis";
}
}
}
AutoLabel inherits to the label control, the default width is "100%", and when the AutoLabel is placed in the container class element, the width of its contents is automatically adjusted by the container size. And when the AutoLabel appears with the "..." number, the mouse is placed above it, and its ToolTip automatically displays the full contents. The following figure:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.