Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tooltip computed links for asp button after button is clicked

Tags:

jquery

c#

asp.net

<ItemTemplate>
  <tr>
  <asp:LinkButton ID="btnID" runat="server"  
   ToolTip='The calculated IDs are: ' OnCommand="showIds"
   CommandArgument='<%# Convert.ToInt32(Eval("Year")) + "," +   
   Convert.ToInt32(Eval("Month")) %>'>
  <%# Convert.ToInt32(Eval("Count")) - Convert.ToInt32(Eval("LittleCount"))%>
  </asp:LinkButton>
  </tr>
 </ItemTemplate>

As you can notice the tooltip text is static. In code behind, I do calculate and get some integers ( IDs ) every time the above button is clicked ( protected void showIds(object sender, CommandEventArgs e) { .... }) contained as a List<ExpressionListDictionary>. ( the asp:LinkButton is contained inside an asp:ListView )

What I want to do, is to change the tooltip into a dynamic one, containing all the already obtained IDs as links. ( Something like this: http://jsfiddle.net/IrvinDominin/jLkcs/5/ - but in my case I do need firstly to click the button for calculating the IDs, and after this I would need to change the tooltip text from code as it needs to show the respective IDs, as links if it is possible)

How can I achieve this?

like image 256
Florin M. Avatar asked May 19 '15 07:05

Florin M.


People also ask

How do I make hover tooltip?

Basic Tooltip HTML: Use a container element (like <div>) and add the "tooltip" class to it. When the user mouse over this <div>, it will show the tooltip text. The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" .

How do I show the tooltip on the right side?

Here is how to do it with position: absolute and relative . On the container, set position: relative , and display: table (shrink to fit). For the position: absolute tooltip, set top: 0 , and left: 100% (moves to the right edge of the relative container).

Can we add tooltip in CSS?

You can create custom CSS tooltips using a data attribute, pseudo elements and content: attr() eg.

What is the use of tooltip in asp net?

The ASP.NET Tooltip is a pop-up component. It shows an information or message when you hover, click, focus, or touch an image, button, anchor tag, etc.,. The information displayed in the tooltip can include simple texts, images, hyperlinks, or custom templates.


3 Answers

If you have a class (or id or something) to identify the buttons you can make an jQuery document ready function to change the tooltip with ids to a link containing the ids. I modifyed your fiddle: http://jsfiddle.net/jLkcs/545/

$(document).ready(function () {
     $(".myLinkButton").each(function() {
           createlink(this);
     });
});

function createlink(obj){
   var ids= $(obj).attr('title');
    var linkHtml="<a href='javascript:alert(" + ids + ")'>link</a>"
   $(obj).attr('title',linkHtml);
}
like image 149
Daniel Stackenland Avatar answered Oct 14 '22 18:10

Daniel Stackenland


Why not simply adjust the ToolTip in the codebehind during postback?

protected void showIds(object sender, CommandEventArgs e)
{
    ((LinkButton)sender).ToolTip = "blahblah";
}
like image 3
Serge Shultz Avatar answered Oct 14 '22 18:10

Serge Shultz


You can set your sender attributes if the CommandEventArgs CommandName is equal with your defined one

public void LinkButton_Command(Object sender, CommandEventArgs e)
    {
        if (e.CommandName.Equals("showIds"))
        {
        //
        }
    }

Here is an working example, this will work, not counting in what user control LinkButton is used:

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : Page
{
    public string btnNoTooltip = "No IDs are calculated";
    public string btnTooltip = "The calculated IDs are:";

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void LinkButton_Command(Object sender, CommandEventArgs e)
    {
        if (e.CommandName.Equals("LinkButtonOrder"))
        {
            LinkButton lkTrigger = (LinkButton)sender;
            if (lkTrigger.ToolTip.Equals(btnNoTooltip))
            {
                lkTrigger.ToolTip = btnTooltip + " " + e.CommandArgument;
            }
            else
            {
                lkTrigger.ToolTip += " " + e.CommandArgument;
            }

            Random random = new Random();
            lkTrigger.CommandArgument = random.Next(0, 100).ToString();

            Label1.Text = "Triggered: " + e.CommandName + " with Argument " + e.CommandArgument;
        }
    }
}

Markup:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

     <h3>LinkButton Command Event Example</h3>

      <asp:LinkButton id="LinkButton1" 
           Text="Order Item Here"
           CommandName="LinkButtonOrder"               
           ToolTip='No IDs are calculated'
           CommandArgument="01" 
           OnCommand="LinkButton_Command" 
           runat="server"/>

      <br />

      <asp:LinkButton id="LinkButton2" 
           Text="Or Order Item Here"
           CommandName="LinkButtonOrder"               
           CommandArgument="02"
           ToolTip='No IDs are calculated' 
           OnCommand="LinkButton_Command" 
           Runat="server"/>

      <br />
      <br />

      <asp:Label id="Label1" runat="server"/>
    <asp:PlaceHolder id="plhInjectId" runat="server" Visible="false"></asp:PlaceHolder>
</asp:Content>
like image 3
SilentTremor Avatar answered Oct 14 '22 17:10

SilentTremor