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

reference controls from within a dock's UC

1 Answer 51 Views
Dock
This is a migrated thread and some comments may be shown as answers.
drgorin
Top achievements
Rank 1
drgorin asked on 23 Apr 2009, 07:08 PM

HI,

I have an aspx page that has a table of  both html checkboxes and various asp server controls (some of which are also check boxes).  I gave each of the controls an id of btn_1 thru btn_52.  btn_1 thru btn_32 are the html checkboxes.  btn_33 thru btn_52 are the server controls.  I migrated the table from the aspx to a user control.  I then placed the user control within a raddock that resides on a different aspx. I have a few javascript functions (contained in the user control ascx file) that manipulates attributes of the controls once rendered on the client.  Now that the controls are contained within a user control that is contained within a raddock, I realize that I have to do some drilling down to get a reference to the server side controls on the client. References to the HTML controls do not seem to be a problem.  For example:  I can obtain a reference to btn_1 (an html checkbox) via: var oChk = document.getElementById('btn_1').  But if I want to get a reference to btn_33 ( a server side checkbox), I have to do it with:
 var oChk = document.getElementById("RadDock1_C_ToothPicker1_" + 'btn_33'). I figured this out by "viewing the source code" after the page was rendered.  Is there a more genric way to do this?  I cannot always be certain that my instance of raddock will always be RadDock1 on any given page.  I cannot be certain that my instance of my user control will be ToothPicker1 on any given page.

below please find a sample of my javascript from this project.
<pre>
function

 

AllClear(oButton) {

 

 

 

// adult teeth

 

 

 

var tt = 0;

 

 

 

for (tt = 1; tt <= 32; tt++) {

 

 

 

var oChk = document.getElementById('btn_' + tt)

 

oChk.checked =

 

false;

 

 

}

 

 

// baby teeth

 

 

tt = 0;

 

for (tt = 33; tt <= 52; tt++) {

 

 

 

var oChk = document.getElementById("RadDock1_C_ToothPicker1_" + 'btn_' + tt)

 

 

 

 

 

 

oChk.checked = false;

 

 

}

 

return false;

 

}

</pre>

 

1 Answer, 1 is accepted

Sort by
0
Obi-Wan Kenobi
Top achievements
Rank 1
answered on 27 Apr 2009, 12:59 PM
You could handle the RadDock's OnClientInitialize client event and get its id, e.g.
<%@ register tagprefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" %> 
<%@ Register src="WebUserControl.ascx" tagname="WebUserControl" tagprefix="uc1" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title></title
    <script type="text/javascript"
        function dockInit(dock, args) { 
            var dockId = dock.get_id(); 
            alert(dockId); 
        } 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
    <div> 
        <telerik:RadDockLayout ID="RadDockLayout1" runat="server" > 
                <telerik:RadDock ID="RadDock1" runat="server" OnClientInitialize="dockInit"
                    <ContentTemplate> 
                            <uc1:WebUserControl ID="WebUserControl1" runat="server" />    
                    </ContentTemplate> 
                </telerik:RadDock> 
        </telerik:RadDockLayout> 
    </div> 
    </form> 
</body> 

Tags
Dock
Asked by
drgorin
Top achievements
Rank 1
Answers by
Obi-Wan Kenobi
Top achievements
Rank 1
Share this question
or