Accessing name of control inside of Dock

2 posts, 1 answers
  1. Sean
    Sean avatar
    200 posts
    Member since:
    Nov 2010

    Posted 01 Feb 2011 Link to this post

    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");
        dock.ContentContainer.Controls.Add(ctrl);
    }

    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;
            alert(control);
        }
    </script>

    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);
                <%=Page.GetPostBackEventReference(btnHidden_Charts)%>;
        }
    </script>

    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.

    Thanks,

    Sean
  2. Answer
    Pero
    Admin
    Pero avatar
    1156 posts

    Posted 03 Feb 2011 Link to this post

    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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="RadScriptManager1" runat="server">
        </asp:ScriptManager>
        <script type="text/javascript">
            //Put your JavaScript code here.
        </script>
        <div>
            <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"
                        Height="300px">
                        <ContentTemplate>
                            <asp:Label ID="Label1" Text="This is a Label in dock" runat="server" ClientIDMode="Static" />
                        </ContentTemplate
                    </telerik:RadDock>
                </telerik:RadDockZone>
            </telerik:RadDockLayout>
        </div>
        </form>
    </body>
    </html>


    Greetings,
    Pero
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top