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

Trying to close RadDock in Javascript

1 Answer 62 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 15 Feb 2011, 09:54 PM
I have a module within DotNetNuke that contains a RadMenu and a RadDock.  Items in the menu correspond to some of the RadDocks.  For example, one of the RadDocks is named Dock_MyTasks.  I can pull that name from the RadMenuItem value field.  But when I try to use that name to $Find the Dock control I have problems.  First, DNN adds to the Dock_MyDocks name like this ...

dnn_ctr381_Que2_Dock_MyTasks.  

 

I get around that by calling a Javascript function that returns a control containing the name Dock_MyTasks.  But, when I look at the running HTML, there are multiple HTML elements that contain the name Dock_MyTasks.  They are suffixed with _T, _C, _ClientState.  Here's the JavaScript I'm trying to use.  Everyhing seems to execute just fine until I call the GetClientId function.  What am I doing wrong?

 

 

 

 

 

 

 

 

 

 

function miClicked(sender, e) {

var MenuItem = e.get_item();

var DockName = MenuItem.get_value();

var dock = GetClientId(DockName);

var isClosed = dock.get_closed();

dock.set_closed(!isClosed);

MenuItem.Selected = !MenuItem.Selected;

}

 


// Gets the ASP.NET generated control ID

 

function GetClientId(controlId) {

var count = document.forms[0].length;

var i = 0;

var aspControlId;

for (i = 0; i < count; i++) {

aspControlId = document.forms[0].elements[i].id;

pos = aspControlId.indexOf(controlId);

if (pos >= 0) break;

 

 

}
return document.forms[0].elements[i];

 

}

 

1 Answer, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 17 Feb 2011, 02:41 PM
Hi Rick,

The easiest way to find the correct dock, would be to store its ClientID in the corresponding RadMenuItem. If this is not possible, modify your GetClientId method to check whether the className contains the "RadDock" string. The modified code will look like the following:
function GetClientId(controlId)
{
    var count = document.forms[0].length;
    var aspControlId;
    for (var i = 0; i < count; i++)
    {
        var currentElement = document.forms[0].elements[i];
        aspControlId = currentElement.id;
        pos = aspControlId.indexOf(controlId);
        if (pos >= 0 && currentElement.className.indexOf("RadDock") != -1)
            break;
    }
    return aspControlId;
}

Now, if you want to get a reference to the dock, simply use the $find method and pass the RadDock's client id.

Kind regards,
Pero
the Telerik team
Tags
Dock
Asked by
Rick
Top achievements
Rank 1
Answers by
Pero
Telerik team
Share this question
or