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

Rad Tooltip Manager - User control with script tag not working

6 Answers 221 Views
ToolTip
This is a migrated thread and some comments may be shown as answers.
Kishan Gandikota
Top achievements
Rank 1
Kishan Gandikota asked on 04 Mar 2010, 09:24 PM
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

6 Answers, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 08 Mar 2010, 03:38 PM
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.
0
Kishan Gandikota
Top achievements
Rank 1
answered on 08 Mar 2010, 04:46 PM
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
0
Svetlina Anati
Telerik team
answered on 11 Mar 2010, 03:00 PM
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.
0
Kishan Gandikota
Top achievements
Rank 1
answered on 20 Mar 2010, 03:01 AM
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
0
Kishan Gandikota
Top achievements
Rank 1
answered on 20 Mar 2010, 03:55 AM
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
0
Tsvetie
Telerik team
answered on 26 Mar 2010, 01:29 PM
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.
Tags
ToolTip
Asked by
Kishan Gandikota
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Kishan Gandikota
Top achievements
Rank 1
Tsvetie
Telerik team
Share this question
or