Rad Tooltip Manager - User control with script tag not working

7 posts, 0 answers
  1. Kishan Gandikota
    Kishan Gandikota avatar
    44 posts
    Member since:
    Sep 2009

    Posted 04 Mar 2010 Link to this post

    Hi,

    I have a RAD Tooltip manager in my code that opens up the user control. Problem is my user control has a script tag and this tag is not getting executed. I will explain you in detail below.

    Default.aspx
    <asp:ScriptManager ID="safd" runat="server">  
        </asp:ScriptManager> 
        <div> 
            <asp:HyperLink ID="hypTooltip" runat="server" NavigateUrl="#" Text="Tooltip" /> 
            <telerik:RadToolTipManager ID="radToolTipManager" runat="server" OffsetY="-7" OffsetX="10" 
                Width="300" Height="300" RelativeTo="Element" Position="Center" HideEvent="ManualClose" 
                ShowEvent="OnClick" ManualClose="True" OnClientShow="OnClientShowTooltipMessage" 
                OnAjaxUpdate="radToolTipManager_AJAXUpdate">  
            </telerik:RadToolTipManager> 
        </div> 
    Default.aspx.cs
    protected void Page_Load(object sender, EventArgs e)  
            {  
                if (!Page.IsPostBack)  
                {  
                    radToolTipManager.TargetControls.Add(hypTooltip.ClientID, true);  
                }  
            }  
     
            protected void radToolTipManager_AJAXUpdate(object sender, ToolTipUpdateEventArgs e)  
            {  
     
                Control ctrToolTip = Page.LoadControl("Tooltip.ascx");  
                e.UpdatePanel.ContentTemplateContainer.Controls.Add(ctrToolTip);  
            } 

    Tooltip.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Tooltip.ascx.cs" Inherits="WebApplication5.Tooltip" %> 
    <div> 
        Inside Div  
     
        <script type="text/javascript" language="javascript" src="http://test.sharevalue.com/company.asp?symbol=MSFT">          
        </script> 
     
    </div> 
    As you see in the ascx page, the url in the script tag generates me the contents. Contents from the Url will look something like this.Please keep in mind this data will be dynamic based on the symbol I pass in the query string.
    Ex:
    document.write('');
    document.write('Home Page');
    document.write('
    Microsoft Corporation  NASDAQ GS: MSFT
    3/04/10 4:00pm 100.63  Change: +0.17 | +0.60%
      1d  | 5d  | 1m  | 3m  | 6m  | 1y
    Open:
    High:
    Volume:
    Yield:
    28.65
    28.65
    28.27
    15.73');
    document.write('');

    The same script tag if I place in aspx page - it works. But if I invoke using Rad Tooltip manager, it doesn't work. It just returns the blank tooltip for me.

    Could someone help me out on this? Do I need to register this script anywhere if I want to use it with RAD Tooltip?
    Regards,
    Kishan G K
  2. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 08 Mar 2010 Link to this post

    Hello Kishan,

    The problem you face is actually not directly related to RadToolTipManager but it is a general MS AJAX issue. When you use AJAX the scripts are not parsed - you can test this by loading your user control in a standard asp update panel in teh same manner as you do with the tooltip manager.

    What I can suggest is to register the client script block from the code behind e.g in similar manner:


    UserControl.ascx:


    <asp:Button ID="btn" runat="server" OnClientClick="InternalCall();return false;" 
     Text="Test" /> 



    UserControl.ascx.cs:

     
    protected void Page_Load(object sender, EventArgs e)  
     {  
      if (Session["registered"] == null)  
      {  
       ScriptManager.RegisterClientScriptBlock(this, GetType(), "btnClick", @"
     function InternalCall() {alert('Javascript declared directly in the user control called form " + btn.ClientID + "');}", true);  
       Session["registered"] = true;  
      }  

    You can find more detailed explanations in the blogpost below:

    http://blogs.telerik.com/tervelpeykov/posts/08-10-20/ajax_using_ajax_to_load_a_usercontrol_that_has_javascript_declared_in_it.aspx

    Other solutions and comments are also available on the net e.g below:

    http://www.google.bg/search?hl=bg&rlz=1W1WZPA_en&q=javascript+update+panel+user+control&meta=&aq=f&oq=

    All the best,
    Svetlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kishan Gandikota
    Kishan Gandikota avatar
    44 posts
    Member since:
    Sep 2009

    Posted 08 Mar 2010 Link to this post

    Hello Svetlina,

    Thanks for your response. I am not sure if I can solve the problem by using RegisterClientScriptBlock.

    Only thing I have in ascx is "script tags". I have pasted my code below.

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Tooltip.ascx.cs" Inherits="WebApplication5.Tooltip" %> 
    <div> 
        <script type="text/javascript" language="javascript" src="http://test.sharevalue.com/company.asp?symbol=MSFT">          
        </script> 
    </div> 

    I don't have any functions inside the script block. Script block is empty expect that it has src attribute with the appropriate URL. That is it.

    Your timely help on this is appreciated.

    I tried to put asp:updatePanel for this script tag and manually did .update() on the server side. Even this didn't work.

    Regards,
    Kishan G K
  5. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 11 Mar 2010 Link to this post

    Hello Kishan,

    There are many manners to put the script registration from the server. The easiest one is the following:

    1) Set runat="server" for the main page's head
    2) Add the script to the header if it still not added:

    this.Page.Header.Controls.Add(new LiteralControl("<script src='MyScript.js' type='text/javascript'></script>"));



    Best wishes,
    Svetlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Kishan Gandikota
    Kishan Gandikota avatar
    44 posts
    Member since:
    Sep 2009

    Posted 19 Mar 2010 Link to this post

    Hello Svetlina,

    I think I am not clear with my earlier email.

    I have a user control inside where I have to register script.  Script doesn't have any code inside it and it is just having <script> tag with source 'src' attribute to it. The URL that I have given in the script tag will generate the html to show on the user control. My problem is this 'http' information is not coming up since we need to register this script. But I am not able to register just this script...

    If you alternate solutions, could you please help me on this?


    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Tooltip.ascx.cs" Inherits="WebApplication5.Tooltip" %> 
    <div> 
        Inside Div  
     
        <script type="text/javascript" language="javascript" src="http://test.sharevalue.com/company.asp?symbol=MSFT">          
        </script> 
     
    </div>


    Regards,
    Kishan G K
  7. Kishan Gandikota
    Kishan Gandikota avatar
    44 posts
    Member since:
    Sep 2009

    Posted 19 Mar 2010 Link to this post

    Hi Svetlina,

    Just to add more information,

    adding this code: 
    Page.ClientScript.RegisterClientScriptInclude("Global/jquery", "http://test.sharevalue.com/company.asp?symbol=MSFT");

    will generate the script elements only to my page. But I want it to appear in my RAD user control. I have attached a screenshot to better understand the problem.

    As you can see from the screenshot - when I select tooltip hyperlink - my tooltip appears. Below is the code for my tooltip user control.

    tooltip.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Tooltip.ascx.cs" Inherits="WebApplication5.Tooltip" %> 
    <div> 
        Inside Div  
     
        <script type="text/javascript" language="javascript" src="http://test.sharevalue.com/company.asp?symbol=MSFT">          
        </script> 
     
    </div>
    Tooltip Window

    Only the text "Inside Div" and "Tooltip Window" is appearing. The content of the script tag is not appearing. Using the registerclientscriptblock is only showing those information on the main page and not on the tooltip. 

    Note: For security, I have changed the Url in the script tag. Actual url would be something different.

    Regards,
    Kishan G K
  8. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 26 Mar 2010 Link to this post

    Hello Kishan Gandikota,
    I can help you evaluate the code that you register with the SCRIPT tag, but even if you do this, the document.write method will not do what you expect it to. Basically, the document.write command must be carried out during the loading of the page. That is why, you will have to update your code to use another approach to show the information in the UserControl - for example, the innerHTML property of a DIV element. For example:

    UserControl:
    Here
     
    <div id="addContentHere"></div>
     
    Here

    javascript:
    contentWrapperElement.innerHTML = "test content";

    You can use the following code to create your script tag:
    string script = @"
                    var contentWrapperElement = $get('addContentHere');
                    var scriptElement = document.createElement('script');
                    scriptElement.type = 'text/javascript';
                    scriptElement.language = 'javascript';
                    scriptElement.src = 'ScriptInUpdatePanel.js';
                    contentWrapperElement.appendChild(scriptElement);";
    ScriptManager.RegisterStartupScript(this, this.GetType(), script, script, true);

    I have attached a simple test page to demonstrate my idea. Feel free to modify the code so that it meets your requirements.

    Regards,
    Tsvetie
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017