简体   繁体   English

通过C#代码中的方法在ASP.net中设置的工具提示

[英]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 ToolTip =“ <%#methodname(parameter)%>”-这会出错

  • 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. 您可以在代码后面做一些事情,例如在preRender阶段将Tooptip设置为等于Label的Text。

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. 或另一种较简单的方法是将标签设为ReadOnly TextBox并在其上附加一个方法“ OnTextChanged”,然后在其中设置工具提示...如果您不介意该字段看起来像文本框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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