This is a migrated thread and some comments may be shown as answers.

Adding Tooltips to CheckboxList

4 Answers 127 Views
ToolTip
This is a migrated thread and some comments may be shown as answers.
Chad Johnson
Top achievements
Rank 1
Chad Johnson asked on 30 Jul 2009, 03:10 PM
Greetings,

I have a checkboxlist on a page to which I am trying to add tooltips to.  I finally managed to find some code that placed them onto it during the load of the page, but whenever I do a postback, they will not return, no matter what I seem to do to them.  Here is the code for what I'm doing.

//I cut out part of the code that does other things, but this is basically the same  
protected void Page_Load(object sender, EventArgs e)  
        {  
            if (!IsPostBack)  
                //CoP is just a Session variable that is pulled into a property  
                LoadValues(CoP);  
 
            LoadTooltips();  
        }  
 
//Called after checkboxlist is built  
private void LoadTooltips()  
        {  
            foreach (ListItem li in cblModules.Items)  
            {  
                var moduleHit = (from a in CoP.Modules where a.ModuleID == Int32.Parse(li.Value) select a.Description).FirstOrDefault();  
 
                if (!string.IsNullOrEmpty(moduleHit))  
                    ToolTipify(li, moduleHit);  
            }  
        } 

When the OnSelectedIndexChanged event is fired, LoadTooltips is called at the end to rebuild the Tooltips for the cblModules.  Unfortunately, nothing happens.  Here is the code I use to build the Tooltips if it helps.

private void ToolTipify(ListItem li, string description)  
        {  
            ContentPlaceHolder con = (ContentPlaceHolder)Master.Master.FindControl("cphContent2");  
            ContentPlaceHolder con1 = (ContentPlaceHolder)con.FindControl("cphCCMContent");  
            RadToolTip tip = new RadToolTip();  
 
            li.Attributes.Add("ID", Guid.NewGuid().ToString());  
              
            tip.RelativeTo = ToolTipRelativeDisplay.Element;  
            tip.Text = description;  
            tip.TargetControlID = li.Attributes["ID"];  
            tip.IsClientID = true;  
            con1.Controls.Add(tip);  
        } 

Again, it works on the first time through, when there is no Postback, but when I cause a Postback (clicking on cblModules), the tooltips vanish.  If anyone has any ideas or a better solution, I'd be very appreciative.

~Chad Johnson

4 Answers, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 04 Aug 2009, 12:18 PM
Hi Chad,

When you dynamically create an dadd controls to a page, you should take care to recreate them again on postback and this is not directly related to RadControls but it is a general ASP.NET knowledge. In your code you never recreate the tooltips, at least in the code snippets you have provided. You can find more information about dynamic creation of controls in ASP.NET below:

http://msdn.microsoft.com/en-us/library/kyt0fzt1(VS.80).aspx

Recreating controls after postback - part I and II. Additioanl information is also available on the net. 


Best wishes,
Svetlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Chad Johnson
Top achievements
Rank 1
answered on 10 Aug 2009, 01:38 PM
I am rebuilding the control on the Postback.  Note that in the Page_Load, I have LoadTooltips() below the !IsPostBack.  That is called everytime the page loads.  This works fine on another page, but this specific page has issues with it.
0
Svetlina Anati
Telerik team
answered on 13 Aug 2009, 08:17 AM
Hi Chad,

I prepared a sample demo based on your code and attached it to the thread. Please, examine it and in case you need further assistance, let me know what changes should I apply to reproduce the problem locally.


Kind regards,
Svetlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Chad Johnson
Top achievements
Rank 1
answered on 13 Aug 2009, 10:55 AM
Thanks for the code sample, but that is pretty much the exact same thing I put up in the first place.  It didn't really help me out, but I did find the solution on my own.  It seems that whenever the CheckBoxList was updated on the Postback, the RadAjaxManager was killing off the Tooltips.  Once I took it out of it, the Tooltips stuck.  Thanks once more.
Tags
ToolTip
Asked by
Chad Johnson
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Chad Johnson
Top achievements
Rank 1
Share this question
or