开发者

Add icon to Text field in Label control

I want to know if there is a way I can add an icon to asp.net Label's Text.

So, so开发者_JS百科mething like

<asp:Label run="server"
Text= "Please see the "icon" below />

Thanks.


You can't use the text property this way - the Text string will terminate with the " before the word icon.

However, any HTML markup will not be escaped, so you can use an <img> tag.

<asp:Label run="server"
   Text="Please see the <img src='icon.gif' /> below" />

From MSDN (Label.Text):

The Text property can include HTML. If it does, the HTML will be passed unchanged to the browser, where is might be interpreted as markup and not as text.

Alternatively, you can add an asp:image to your markup, or place one between two Label controls.


No. There is not a property such as icon or image in asp label. Here is the syntax and options available in asp.net label

<asp:Label
    AccessKey="string"
    AssociatedControlID="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CssClass="string"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    Height="size"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    Text="string"
    ToolTip="string"
    Visible="True|False"
    Width="size"
/>


There is no direct way.

However you can use simple HTML <label> tag with for="id" attribute attached to ImageButton for instance

<asp:ImageButton ID="ToggleButton" runat="server" ImageUrl="~/images/expand.gif" onclick="ToggleButton_Click" />
<label ID="ToggleButtonLabel" for="ToggleButton" runat="server">Range Summary</label>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜