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

Accessing name of control inside of Dock

1 Answer 36 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 2
Sean asked on 02 Feb 2011, 01:28 AM
Hi Telerik,

I have a dynamically created Dock and its content is a chart. I load the content for the dock like so:

private void LoadDockContent(RadDock dock)
    System.Web.UI.Control ctrl = Page.LoadControl("PowerUsage.ascx");

I need to be able to access the name of the control ClientSide.

I suspect it's something like this, but I'm not quite on:

<script type="text/javascript">
    function OnClientInitialize(dock, args) {
        var content = dock.get_contentContainer();
        var control = $telerik.isIE ? content.childNodes[0].innerHTML : content.childNodes[1].innerHTML;

The alert displays a dump of all the HTML in the dock. This does include the control I am looking for, but there would be some extremely heavy parsing necessary to isolate the string that I want from the HTML. I've attached to this post "html.png" which is the output of the alert.

If I could just get the img id instead of all the HTML I would be happier, but I would be happiest if I could capture the control name without any parsing, obviously. Ultimately, my goal is to utilize some jQuery to resize the chart control stored on the RadDock. Just to make sure I'm not headed down a dark path, I would also just like to get a quick, "Yep. That should work!" from you guys.

<script type="text/javascript">
    jQuery(function($) {
            $(window).wresize(SetPageChartSizes<%= Chart.ClientID %>);
            SetPageChartSizes<%= Chart.ClientID %>();
        function SetPageChartSizes<%= Chart.ClientID %>() {
            document.getElementById('<%= hfChartWidth.ClientID %>').value = (document.getElementById('<%= updatePanel.ClientID %>').offsetWidth - 4);

So, this code isn't 100% relevant to what I've got going on, yet. This function waits for the window to be resized and then resizes Chart based on the new window size. I am going to rewrite this so that whenever the size of the Dock changes the content it controls (a chart) will resize to fill the size of the dock. Chart doesn't just exist on the page, though. I have to get a handle on that -- which means I need to get the control name from the Dock.

Let me know if anything here is unclear.



1 Answer, 1 is accepted

Sort by
Telerik team
answered on 03 Feb 2011, 04:22 PM
Hi Sean,

The client id of the server controls placed in the RadDock is composed in the following way:
dock.ClientID + "_C_" + control.ClientID.
If you had a label with ID="Label1", and the dock had ID="RadDock1", the client id of the label would be RadDock1_C_Label1.
I believe the easiest way to find the element on the client would be to set the ASP.NET 4.0 ClientIDMode property to Static, on the respective control. Here is an example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<head runat="server">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="RadScriptManager1" runat="server">
    <script type="text/javascript">
        //Put your JavaScript code here.
        <telerik:RadDockLayout ID="RadDockLayout1" runat="server">
            <telerik:RadDockZone ID="RadDockZone1" runat="server" MinHeight="300px" Width="300px">
                <telerik:RadDock ID="RadDock1" runat="server" Title="RadDock-Title" Width="300px"
                        <asp:Label ID="Label1" Text="This is a Label in dock" runat="server" ClientIDMode="Static" />

the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Asked by
Top achievements
Rank 2
Answers by
Telerik team
Share this question