3

我研究了一种动态显示工具提示的好方法,发现OverLibWrapper正是我所需要的。

我将所有工具提示数据存储在自定义配置部分中,工具提示在Page_Load.

我做了一个快速测试并且工作正常。当我意识到 OverLibWrapper 不适用于母版页时,问题就出现了。我们的网站使用了很多母版页,因此不能将它们删除。

我想知道是否可以使用像 OverLibWrapper 这样的东西。

编辑:

我正在寻找的是一个控件,可以在鼠标悬停时立即显示漂亮的工具提示,最好像 overlib 一样立即以动态方式显示(没什么特别的,因为我只是显示原始文本),因为 ASP.NET 中的工具提示属性不是很漂亮并需要一段时间才能出现。例如,假设我有一个消息集合:

class Message
{
    string ctrlid, msgtodisplay;
}

当页面加载时:

TooltipManager manager;
foreach(var m in messages)
{
    Tooltip tltp=new Tooltip;
    m.ControlID=m.ctrlid;
    m.Message=m.msgtodisplay;
    manager.AddTooltip(tltp);
}

所以基本上是提供 Tooltip 和 TooltipManager 功能的东西。

4

2 回答 2

1

看看这个:

注释工具提示

我认为这将满足您的需求。

你有没有想过只写自己的?有时我发现其他人的东西永远不适合我的需要。

于 2010-10-20T08:15:15.463 回答
1

好吧,我终于解决了我的问题:

我已经使用功能来查找任何控件(适用于母版页):

public static Control FindControlRecursive(Control root, string id)
{
    if (id == string.Empty)
        return null;

    if (root.ID == id)
        return root;

    foreach (Control c in root.Controls)
    {
        Control t = FindControlRecursive(c, id);
        if (t != null)
            return t;
    }
    return null;
}

而这个方法:

public static void load(Page page, string pageFileName)
{
    foreach (ConfiguracionElem elem in Configuracion.GetConfig(pageFileName).Tooltips)
    {
        WebControl ctrl = (WebControl)FindControlRecursive(page, elem.controlid);
        if (ctrl == null)
            throw new ControlNotFoundException("There's no control'"+elem.controlid+"'")
        else
        {
            ctrl.Attributes.Add("onmouseover","return overlib('"+elem.message+"');");
            ctrl.Attributes.Add("onmouseout","return nd();");
        }
    }
}

I added the Overlib library manually to a script folder, then I iterated through my Custom Configuration Section (where my tooltip data is stored) to add the javascript attributes dynamically.

于 2010-12-13T23:32:17.080 回答