简体   繁体   中英

Tooltip set in ASP.net by method in c# code

trying to get same string on tooltip as is in the "Text" eg
Text="<%# methodname(parameter) %>"
ToolTip="<%# methodname(parameter) %>" - this however errors out

  • Text is not static - dependent on string returned in method

     <HeaderTemplate> <asp:Label ID="Header" runat="server" Text="<%# methodname(parameter) %>" meta:resourcekey="HeaderResource1"></asp:Label> </HeaderTemplate> 

any help would be really appreciated

protected string methodname(int integer)
{
    switch (integer)
    {
        case 1:
            return RadtxtLot1.Text.Trim();
        case 2:
            return RadtxtLot2.Text.Trim();
        case 3:
            return RadtxtLot3.Text.Trim();
        default:
            return "";
    }
}

You could do something in your code behind like setting the Tooptip equal to the Text of the Label in your preRender stage.

Or another less tidy way would be to make your label a ReadOnly TextBox and attach a method on it "OnTextChanged" then set the Tooltip in that... if you don't mind that field looking like a text box.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM