[CLOSED] Tooltip With Dynamically created content

  1. #1

    [CLOSED] Tooltip With Dynamically created content

    I have a page that that I load a list of contacts into a display field. I wrap a span around each contact and then would like to assign a tooltip to each span. How can I make sure the tooltip is positioned next to the item? The example below works, but the tooltip shows up above and not to the right. This is due to the css positioning that is used in the css class called status-icon, which I pulled from your examples. How could I do this dynamically?

    <%@ Page Language="C#" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack && !X.IsAjaxRequest)
            {
                pnlForm.Title = "A test";
                lblNumber.Text = "000001";
                txtBody.Text = "This is a test";
                txtSubject.Text = "A test";
                btnCancel.Visible = false;
                btnDelete.Visible = true;
     
                LoadRequestors();
            }
        }
     
        public void LoadRequestors()
        {
            int count = 0;
            List<string> requestors = new List<string>();
     
            {
                string spanid = string.Format("sp_{0}", 1);
                requestors.Add(count > 0 ?
                    " <span id='" + spanid + "'>" + "Johnny Tester" + "</span>" :
                    "<span id='" + spanid + "'>" + "Johnny Tester" + "</span>");
     
                //Add a tooltip
                ToolTip tip = new ToolTip();
                tip.ID = "tt_" + spanid;
                tip.Target = spanid;
                tip.Title = "Contact Info";
                tip.Anchor = "Left";
                tip.Width = new Unit(200, UnitType.Pixel);
                tip.AutoHide = false;
                tip.Closable = true;
                tip.Delegate = "span";
     
                ContactInfoTemplate template = new ContactInfoTemplate();
                template.MyContact = new Contact() { DisplayName = "Johnny Tester", Phone = "770-990-8765", Email = "test@testing.com" };
                template.ElementId = spanid;
                tip.Content = template;
     
                this.Controls.Add(tip);
            }
     
            count++;
     
            {
                string spanid = string.Format("sp_{0}", 2);
                requestors.Add(count > 0 ?
                    " <span id='" + spanid + "'>" + "Timmy Tester" + "</span>" :
                    "<span id='" + spanid + "'>" + "Timmy Tester" + "</span>");
     
                //Add a tooltip
                ToolTip tip = new ToolTip();
                tip.ID = "tt_" + spanid;
                tip.Target = spanid;
                tip.Title = "Contact Info";
                tip.Anchor = "Left";
                tip.Width = new Unit(200, UnitType.Pixel);
                tip.AutoHide = false;
                tip.Closable = true;
                tip.Delegate = "span";
     
                ContactInfoTemplate template = new ContactInfoTemplate();
                template.MyContact = new Contact() { DisplayName = "Timmy Tester", Phone = "770-584-8765", Email = "test@gmail.com" };
                template.ElementId = spanid;
                tip.Content = template;
     
                this.Controls.Add(tip);
            }
     
            string toReturn = String.Empty;
            requestors.ForEach(s => toReturn += s + ";");
            lblRequestor.Text = toReturn.TrimEnd(';');
        }
     
        public class ContactInfoTemplate : ITemplate
        {
            public Contact MyContact { get; set; }
            public string ElementId { get; set; }
     
            public void InstantiateIn(Control container)
            {
                // load controls 
                Literal lit = new Literal();
                lit.Text = @"
                        <div id='content-tip_" + ElementId + @"'>
                            <strong>" + MyContact.CompanyName + @"</strong>
                            <table padding='2'>
                                <tr>
                                    <td>Phone 1:</td>
                                    <td><a href='javascript:parent.Ext.net.DirectMethods.createPhoneCall(" + MyContact.ContactId.ToString() + "," + MyContact.ContactObjectTypeId.ToString() + ")'>" + MyContact.Phone + @"</a></td>
                                </tr>
                                <tr>
                                    <td>Email:</td>
                                    <td><a href='javascript:parent.Ext.net.DirectMethods.createEmail(" + MyContact.ContactId.ToString() + "," + MyContact.ContactObjectTypeId.ToString() + ")'>" + MyContact.Email + @"</a></td>
                                </tr>
                                <tr>
                                    <td>Email 2:</td>
                                    <td><a href='javascript:parent.Ext.net.DirectMethods.createEmail(" + MyContact.ContactId.ToString() + "," + MyContact.ContactObjectTypeId.ToString() + ")'>" + MyContact.Email2 + @"</a></td>
                                </tr>
                            </table>
                        </div>";
                container.Controls.Add(lit);
            }
        }
     
        public class Contact
        {
            public string DisplayName { get; set; }
            public string Email { get; set; }
            public string Email2 { get; set; }
            public string CompanyName { get; set; }
            public string Phone { get; set; }
            public int ContactId { get; set; }
            public int ContactObjectTypeId { get; set; }
     
            public Contact()
            {
     
            }
        }
    </script>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Testing</title>
        <style type="text/css">
            /* Tooltip Styles */
            #content-anchor-tip ul
            {
                float: left;
                width: 200px;
                list-style-type: disc;
                margin-left: 15px;
            }
            
            .ext-ie #content-anchor-tip ul
            {
                margin: 0;
                padding-left: 15px;
            }
            
            #content-anchor-tip .thumb
            {
                float: right;
            }
            
            #content-anchor-tip .status-icon
            {
                position: absolute;
                top: 4px;
                right: 50px;
                padding: 0;
                line-height: 0;
            }
            
            #content-anchor-tip a:link, #content-anchor-tip a:visited
            {
                color: #339;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Gray">
        </ext:ResourceManager>
        <ext:FormPanel ID="pnlForm" runat="server" Layout="FormLayout" Padding="5" Border="false" MonitorValid="true" Icon="Page" Collapsible="true" AutoScroll="true" Height="450">
            <Defaults>
                <ext:Parameter Name="msgTarget" Value="side" Mode="Value">
                </ext:Parameter>
            </Defaults>
            <TopBar>
                <ext:Toolbar ID="tbRibbon" runat="server">
                    <Items>
                        <ext:Button ID="btnEdit" runat="server" Text="Edit Ticket" IconAlign="Left" Icon="TableEdit">
                        </ext:Button>
                        <ext:Button ID="btnSaveClose" runat="server" Text="Save Ticket" IconAlign="Left" Icon="Disk">
                        </ext:Button>
                        <ext:Button ID="btnCancel" runat="server" Text="Oops! Cancel" IconAlign="Left" Icon="Stop">
                        </ext:Button>
                        <ext:Button ID="btnDelete" runat="server" Text="Delete Ticket" IconAlign="Left" Icon="Delete">
                        </ext:Button>
                        <ext:Button ID="btnAttachFile" runat="server" Text="Attach File" IconAlign="Left" Icon="Attach">
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <Items>
                <ext:TextField ID="txtSubject" runat="server" FieldLabel="Subject" Width="600" AllowBlank="false">
                </ext:TextField>
                <ext:Label ID="lblNumber" runat="server" FieldLabel="Ticket Number">
                </ext:Label>
                <ext:DisplayField runat="server" ID="lblRequestor" FieldLabel="Requestor(s)">
                </ext:DisplayField>
                <ext:HtmlEditor ID="txtBody" runat="server" FieldLabel="Body" Width="600">
                </ext:HtmlEditor>
            </Items>
        </ext:FormPanel>
        </form>
    </body>
    </html>
    Last edited by Daniil; Feb 14, 2012 at 2:26 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please replace:
    tip.Anchor = "Left";
    with
    tip.Anchor = "left";
    Also you can remove .Delegate property since you don't use it setting up a separate span element for each ToolTip.

    As well, you can remove the CSS styles at all since they are not used at all. I mean that there is no an HTML element on the page which would satisfy the "#content-anchor-tip" selector.
  3. #3
    Quote Originally Posted by Daniil View Post
    As well, you can remove the CSS styles at all since they are not used at all. I mean that there is no an HTML element on the page which would satisfy the "#content-anchor-tip" selector.
    We have replaced
    #content-anchor-tip
    with
    #ContentAnchorTip
    in our example
    https://examples1.ext.net/#/Miscella...Tips/Overview/
  4. #4
    Ok, that works thanks

Similar Threads

  1. [CLOSED] How to clean up dynamically created controls?
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 23, 2011, 9:51 AM
  2. [CLOSED] Reload store created dynamically
    By stoque in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Aug 18, 2011, 5:07 PM
  3. Dynamically created panel content
    By reiben in forum 1.x Help
    Replies: 0
    Last Post: Jun 14, 2011, 7:07 AM
  4. [CLOSED] AutoExpandColumn on dynamically created column
    By wazige in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 11, 2011, 2:02 PM
  5. [CLOSED] [1.0] Dynamically created control problem
    By galeb in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Aug 19, 2010, 7:16 AM

Posting Permissions