我希望工具提示始终与 ASP 文本框的文本相同。我当然可以写
AnyTextBox.Text = "any text";
AnyTextBox.ToolTip = "any text";
但我不想重复数百个赋值语句。 我也可以为 Text 属性编写更改事件处理程序,但我不想为此编写许多事件处理程序(如果有更优雅的解决方案)
有吗?像这样:
<asp:TextBox ID="AnyTextBox" runat="server" ToolTip="binding magic goes here, but how?">
提前致谢
最佳答案
您可以编写自己的继承自 TextBox 的自定义控件吗?我使用 Text 属性来设置工具提示,但如果需要,您也可以反过来设置。
控制:
public class TooltipTextBox : TextBox {
public new string Text {
get { return base.Text; }
set
{
base.Text = value;
this.ToolTip = value;
}
}
}
标记:
<my:TooltipTextBox ID="AnyTextBox" runat="server" Text="binding magic goes here">
关于c# - 如何将 ASP TextBox 的文本绑定(bind)到它的工具提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19403267/