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

Dynamic creation of Tooltip manager ...

4 Answers 237 Views
ToolTip
This is a migrated thread and some comments may be shown as answers.
Henrik Brinch
Top achievements
Rank 2
Henrik Brinch asked on 26 Jul 2007, 06:42 PM
Can anyone tell me if this is the correct way to dynamically create the tooltip for a control (I have a Panel on the page):

 

    protected void Page_Load(object sender, EventArgs e)  
    {  
      ScriptManager scriptManager = new ScriptManager();  
      scriptManager.ID = "MyScriptManager";  
      this.Panel1.Controls.Add(scriptManager);  
 
      Label lab1 = new Label();  
      lab1.Text = "Dette er min test tekst";  
      lab1.ID = "MyTest";  
      this.Panel1.Controls.Add(lab1);  
 
      Telerik.Web.UI.RadToolTipManager toolTipMngr = new Telerik.Web.UI.RadToolTipManager();  
      toolTipMngr.AjaxUpdate += new Telerik.Web.UI.ToolTipUpdateEventHandler(toolTipMngr_AjaxUpdate);  
      toolTipMngr.TargetControls.Add("MyTest");  
      this.Panel1.Controls.Add(toolTipMngr);  
 
 
    }  
 
    void toolTipMngr_AjaxUpdate(object sender, Telerik.Web.UI.ToolTipUpdateEventArgs e)  
    {  
      e.UpdatePanel.Controls.Add(new HtmlGenericControl("hr"));  
    }  
 

4 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 27 Jul 2007, 03:25 PM
Hi Henrik,

Thank you for pointing out this issue. We will research it and we will provide more information about it in the beginning of next week.

Currently, you can use the solution provided in the attached sample project.

Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Henrik Brinch
Top achievements
Rank 2
answered on 27 Jul 2007, 08:38 PM
Hi Rumen,

Sorry, but I don't quite understand how your solution below will solve my problem (the parts of interest, are those commented out?! :-):

using System;  
using System.Data;  
using System.Configuration;  
using System.Collections;  
using System.Web;  
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.WebControls.WebParts;  
using System.Web.UI.HtmlControls;  
 
public partial class Default3 : System.Web.UI.Page  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        //ScriptManager scriptManager = new ScriptManager();  
        //scriptManager.ID = "MyScriptManager";  
          
        //this.Panel1.Controls.Add(scriptManager);  
 
        Label lab1 = new Label();  
        lab1.Text = "Dette er min test tekst";  
        lab1.ID = "MyTest";  
        this.Panel1.Controls.Add(lab1);  
 
        //Telerik.Web.UI.RadToolTipManager toolTipMngr = new Telerik.Web.UI.RadToolTipManager();  
        //toolTipMngr.AjaxUpdate += new Telerik.Web.UI.ToolTipUpdateEventHandler(toolTipMngr_AjaxUpdate);  
        //toolTipMngr.TargetControls.Add("MyTest");  
        //this.Panel1.Controls.Add(toolTipMngr);    
    }  
 
   public void toolTipMngr_AjaxUpdate(object sender, Telerik.Web.UI.ToolTipUpdateEventArgs e)  
    {  
        e.UpdatePanel.ContentTemplateContainer.Controls.Add(new HtmlGenericControl("hr"));  
    }    
}  
 
0
Tervel
Telerik team
answered on 31 Jul 2007, 12:59 PM
Hi Henrik,

Please excuse us for sending you an incomplete answer.
As can be seen in the attachment, apart from commenting part of your code we also added a RadToolTipManager on the aspx page - because the scenario worked when the manager was added declaratively.

Upon further research what the difference between dynamic and declarative version was we nailed down the problem to the fact that when adding the RadToolTipManager dynamically you did not provide an ID - which ultimately lead to part of the client elements not being properly initialized.
So, one thing you need to do is set the ID.
On our side, we will modify the control's code to either throw an exception or to generate an ID on the fly if ID is not explicitly set. This change will come in effect in the next Prometheus update.

The second problem is related to the fact that you should use Page_Init to create the RadToolTipManager, not Page_Load. The reason for this is that when user controls are added to the RadToolTipManager AJAX UpdatePanel (a very common scenario), they need to be re-created at a very early stage of the page lifecycle so that their event handlers (fired by buttons, etc)  are able to execute.


Sincerely yours,
Tervel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Henrik Brinch
Top achievements
Rank 2
answered on 02 Aug 2007, 10:36 AM
Hi Tervel,

Thanks!

For anyone interested here are the working code of a 100% dynamically created tooltip. 

  private RadToolTipManager _tooltipManager;  
 
  protected void Page_Load(object sender, EventArgs e)  
  {  
    Label testLabel = new Label();  
    testLabel.ID = "testlabel";  
    testLabel.Text = "Here some text that needs a tooltip!";  
      
    this.Panel1.Controls.Add(testLabel);  
 
    _tooltipManager.TargetControls.Add("testlabel");  
  }  
 
  protected override void OnInit(EventArgs e)  
  {  
    //  Add the ScriptManager  
    ScriptManager scriptManager = new ScriptManager();  
    scriptManager.ID = "ScriptManager";  
 
    this.Panel1.Controls.Add(scriptManager);  
 
    //  Add the ToolTipManager  
    _tooltipManager = new RadToolTipManager();  
    _tooltipManager.ID = "ToolTipManager";  
    _tooltipManager.AjaxUpdate += new ToolTipUpdateEventHandler(mngr_AjaxUpdate);  
 
    this.Panel1.Controls.Add(_tooltipManager);  
 
    base.OnInit(e);  
  }  
 
  private void mngr_AjaxUpdate(object sender, ToolTipUpdateEventArgs e)  
  {  
    Label tooltipLabel = new Label();  
    tooltipLabel.Text = "Hey it works!!!";  
 
    e.UpdatePanel.ContentTemplateContainer.Controls.Add(tooltipLabel);  
  }  
 

If you can't make it work, please try the following web.config (standard ajax enabled web app):

<?xml version="1.0"?>  
<configuration> 
    <configSections> 
        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">  
            <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">  
                <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>  
                <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">  
                    <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>  
                    <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>  
                    <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>  
                </sectionGroup> 
            </sectionGroup> 
        </sectionGroup> 
    </configSections> 
    <system.web> 
        <pages> 
            <controls> 
                <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
            </controls> 
        </pages> 
        <!--    
          Set compilation debug="true" to insert debugging    
          symbols into the compiled page. Because this    
          affects performance, set this value to true only    
          during development.    
    --> 
        <compilation debug="true">  
            <assemblies> 
                <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
                <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>  
                <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies> 
        </compilation> 
        <httpHandlers> 
            <remove verb="*" path="*.asmx"/>  
            <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
            <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
            <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>  
        </httpHandlers> 
        <httpModules> 
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
        </httpModules> 
    </system.web> 
    <system.web.extensions> 
        <scripting> 
            <webServices> 
                <!-- Uncomment this line to customize maxJsonLength and add a custom converter --> 
                <!--    
      <jsonSerialization maxJsonLength="500">    
        <converters>    
          <add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>    
        </converters>    
      </jsonSerialization>    
      --> 
                <!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. --> 
                <!-- 
        <authenticationService enabled="true" requireSSL = "true|false"/> 
      --> 
                <!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved    
           and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and    
           writeAccessProperties attributes. --> 
                <!--    
      <profileService enabled="true"    
                      readAccessProperties="propertyname1,propertyname2"    
                      writeAccessProperties="propertyname1,propertyname2" />    
      --> 
            </webServices> 
            <!-- 
      <scriptResourceHandler enableCompression="true" enableCaching="true" /> 
      --> 
        </scripting> 
    </system.web.extensions> 
    <system.webServer> 
        <validation validateIntegratedModeConfiguration="false"/>  
        <modules> 
            <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
        </modules> 
        <handlers> 
            <remove name="WebServiceHandlerFactory-Integrated"/>  
            <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
            <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
            <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
        </handlers> 
    </system.webServer> 
</configuration> 
 
Tags
ToolTip
Asked by
Henrik Brinch
Top achievements
Rank 2
Answers by
Rumen
Telerik team
Henrik Brinch
Top achievements
Rank 2
Tervel
Telerik team
Share this question
or