Render Html String in tooltip

蹲街弑〆低调 提交于 2019-12-11 05:38:09

问题


I have a asp.net Calendar. On DayRender event of calendar I want to render html as tooltip.

e.Cell.ToolTip= HttpUtility.HtmlEncode("add<BR>peek") 

But its not working. How to render in browser as html.But it was rendering as

"asdsa&lt;BR&gt;peek"

Edit: I tried like this in another way.

Label b = new Label();
b.Visible = false;
b.Text = "add<BR>peek";
e.Cell.Controls.Add(b); 

Displaying fine. But I want to display label onhover the calendar date. How can I do this? Can any one help me. Thanks in Advance.


回答1:


The easiest way to achieve this would be with jQuery. You need to make the containing cell and the label identifiable to unobtrusive javascript by using css classes. Then you can create a function for when the cell is hovered over which will find the label and display it, then hide when the mouse moves away:

Append the following lines to the server side logic you have already:

b.CssClass = "js-tooltip";
e.Cell.CssClass = "js-tooltip-container";

Your html should then look like (you don't have to code this part, its the result of your code behind):

<td class="js-tooltip-container">
    <label class="js-tooltip" style="display:none;">add <br /> peek</label>
</td>

Then you need to add the following jQuery:

<script type="text/javascript">
$(function(){
    $(".js-tooltip-container").hover(function(){
        $(this).find(".js-tooltip").show();
    }, function(){
        $(this).find(".js-tooltip").hide();
    });
});
</script>

The javascript makes use of the jQuery hover function. This is all boiler plate stuff so if you want something more robust and customisable I would consider using one of the plugins suggested here.



来源:https://stackoverflow.com/questions/12386504/render-html-string-in-tooltip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!