Add dynamic tooltip from code behind in ASP.Net

suhaas121
 
on Aug 12, 2021 12:55 AM
701 Views

Hi

how do i add a tooltip to a string from backend.

 string newstring = "<a> '" + Text + "'</a>";

I am trying to get text from backend and display as hover text.

string searchText = HttpUtility.HtmlEncode(pstext);
string title= patext;
string newstring = "<a title='" + title + "'> '" + pstext + "' </a>";
html = html.Replace(searchText, newstring );

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Aug 16, 2021 02:00 AM

Hi 

You need to use Regular expression to replace the content with highlight color and change text.

Refer below example.

HTML

<asp:HiddenField ID="hfWord" runat="server" />
<asp:HiddenField ID="hfHTML" runat="server" />
<iframe id="frmDisplay" runat="server" frameborder="0" height="500"></iframe>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        var iframeHtml = $("#hfHTML").val();
        $('#frmDisplay').contents().find('body').html(iframeHtml);
    });
</script>

Namespaces

using System.IO;
using System.Text.RegularExpressions;

Code

protected void Page_Load(object sender, EventArgs e)
{
    //Session.Add("Logintype", Session["new"].ToString());
    if (!this.IsPostBack)
    {
        hfWord.Value = "Airplane";
        getpa();
    }
}

public void getpa()
{
    string pstext = "Airplane";
    string patext = "ASPSnippets";
    string html = File.ReadAllText(Server.MapPath("~/HTML.txt"));
    string searchText = HttpUtility.HtmlEncode(pstext);
    string title = patext;
    string newstring = "<span style='background-color:yellow'><a title='" + title + "'>" + pstext + "</a></span>";
    html = Regex.Replace(html, pstext, delegate (Match match) { return newstring; }, RegexOptions.IgnoreCase);
    hfHTML.Value = html;
}

Screenshot