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

set dock.OnClientInitialize dynamically

7 Answers 177 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Adriano
Top achievements
Rank 1
Adriano asked on 04 Sep 2007, 08:08 PM
Hi,

I have been trying to set the dock.OnClientInitialize property in  a loop  dynamically in my code behind.

I am looping through my data source to find how many docks I need to dinacally ad to the zones... I also need to set the OnClientInitialize property inside the same loop.

I though i had it figure out in my javascript that also does some loop but... no matter what I do I always get the "dock has no properties" error message.

Do you have any suggestion on how to do this? If I cold pass the dock id as a parameter it would help but the OnClientInitialize asks for a property and not a method.

Any suggestions?

Thanks,

Adriano

7 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 05 Sep 2007, 06:30 AM
Hello Adriano,

You can set RadDock's OnClientInitialize server-side in the following way:

dock.OnClientInitialize = "OnClientInitialize";

Then in JavaScript the handler looks this way:

function OnClientInitialize(dock, args)
{
      alert(dock.get_id());     
}    

So you have a reference to the dock and can get its ID with dock.get_id(). Hope this helps.

Kind regards,
Petya
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Adriano
Top achievements
Rank 1
answered on 05 Sep 2007, 01:20 PM
Hi Petya,

That helped a lot, but I still having trouble to set the handle from inside a loop. On all my tests the last dock created that gets the set_hadle executed the first ones just donnot. I have try to dinamicly create the javascript function so each dock would have it own function but than i get "dock has no prperties" error. I know it is a timing issue... i just don't know what I am missing.

Here is a example of what I am trying to do:

Code Behind:
for (int i = 0; i < docksTable.Rows.Count; i++)
{
       // Code that instanciate the dock goes here...
       // follow by the OnClientInitialize property:
         dock.OnClientInitialize = "OnClientInitialize";
}
   

ASP/HTML Code:

function OnClientInitialize(dock, args)
{
    var module = $find(dock.get_id()); 
    module.set_handle(document.getElementById("modulePreview"));
}


It all works only for the last instance of the loop.


I apretiate any help,


Adriano
0
Petya
Telerik team
answered on 05 Sep 2007, 02:06 PM
Hi Adriano,

I need just a bit more information to solve the matter. Are you creating your docks and their content dynamically or are they created in .aspx and then you only dynamically set the OnClientinitialize property? And more specifically I need information about the new handle element ("modulePreview") - how do you add it to the dock's content? Providing some more code would be appreciated. It seems to me that for some reason all docks have an element with the same ID - "modulePreview" and this could be why it does not work. Just a remark on your code is that in

function OnClientInitialize(dock, args)
{
    var module = $find(dock.get_id()); 
    module.set_handle(document.getElementById("modulePreview"));
}

you already have the dock as a parameter and you do not need to look for it. You could write

function OnClientInitialize(dock, args)
{
   
dock.set_handle(document.getElementById("modulePreview"));
}


Looking forward to your answer.

Sincerely yours,
Petya
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Adriano
Top achievements
Rank 1
answered on 05 Sep 2007, 05:06 PM
Hi Petya,

The contents of my docks (the title bar and the content) are UserControls (ascx) and they are load dinamically.

The "modulePreview"  the div that contains all the UserCOntrol content to witch i want to set as the handle...

Follow is my full loop code, i can also send you my test solution . As I finish my replay I will follow your suggestion and make the "modulePreview" id in the controls have diferent names. Thanks a lot.

-----------------------------------------------------------------------------
for (int i = 0; i < modulesTable.Rows.Count; i++)
               {

                    // LOAD PAGE MODULES
                    if (zoneID != "Catalog")
                    {
                        LTModule m = new LTModule();
                        LTMemberModule memberModule = (LTMemberModule)LoadControl("~/MemberModules/" + _type.ToString() + ".ascx");

                        m.ModuleType = _type;
                        m.ID = "id" + _type.ToString() + i.ToString();
                        m.UniqueName = "name" + _type.ToString() + i.ToString();
                        m.Title = r["Title"].ToString();
                        m.ModuleZoneID = r["ZoneID"].ToString();
                        m.ModuleZoneIndex = (int)r["ZoneIndex"];
                        m.ContentContainer.Controls.Add(memberModule);
                        m.AutoPostBack = true;
                        m.CommandsAutoPostBack = true;
                        //Currently, there is a problem with the RadDock command items:
                        // if they are not explicitly created, the Command event it not fired.
                        m.Commands.Add(new DockCloseCommand());
                        m.Commands.Add(new DockExpandCollapseCommand());
                        m.Command += new DockCommandEventHandler(Dock_Command);
                        m.DockPositionChanged += new DockPositionChangedEventHandler(DockPositionChanged);

                        rdLayout1.Controls.Add(m);
                        _modulesInPage.Add(m);
                    }
                    else // LOAD CATALOG MODULES
                    {
                        LTModule mpv = new LTModule();
                        UserControl memberModulePreView = (UserControl)LoadControl("~/MemberModulesPreView/" + _type.ToString() + "PreView.ascx");

                        mpv.ModuleType = _type;
                        mpv.ID = "idPreView" + _type.ToString() + i.ToString();
                        mpv.UniqueName = "namePreView" + _type.ToString() + i.ToString();

                        mpv.ModuleZoneID = r["ZoneID"].ToString();
                        mpv.ModuleZoneIndex = (int)r["ZoneIndex"];
                        mpv.DockHandle = DockHandle.None;
                        mpv.ContentContainer.Controls.Add(memberModulePreView);

                        mpv.OnClientInitialize = "OnClientInitialize";

                        mpv.Style.Add("cursor", "move");
                        mpv.Height = new Unit("180px");
                        mpv.AutoPostBack = true;
                        mpv.DockPositionChanged += new DockPositionChangedEventHandler(DockPositionChanged);

                        rdLayout1.Controls.Add(mpv);
                        _modulesInPage.Add(mpv);
                    }
------------------------------------------------------------------------------

Thanks for your help,

Adriano
0
Adriano
Top achievements
Rank 1
answered on 05 Sep 2007, 07:02 PM
Hi Petya,

I want let you know that after follow your suggestion and made my handle id dynamic i got it working. I also had to create a script in code behind for each dock. Here is what I did:

string _dockHandleScript = "<script type='text/javascript' >" +
 "function SetHandleDock" + i.ToString() + "(dock, args){" +
"dock.set_handle(document.getElementById('" + _type.ToString() + "Preview'));}" +
"</script>";

 ScriptManager.RegisterStartupScript(this, this.GetType(), "setHandle" + i.ToString(), _dockHandleScript, false);

dock.OnClientInitialize = "SetHandleDock" + i.ToString();

The functions work fine now.

I appreciate your help and quick answers. I have to say that you guys are doing a great work with Prometheus and on supporting it.

Thanks,

Adriano
LightsTogether.com
0
Petya
Telerik team
answered on 06 Sep 2007, 06:45 AM
Hello Adriano,

Thank you for the nice words, our goal is to satisfy our clients with the products and services we offer. I am very glad that you have solved your problem. Let us know if you still need assistance in your work with our control.

Regards,
Petya
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Rambo the Dog
Top achievements
Rank 1
answered on 12 Mar 2010, 06:53 PM

That's a lot of extra javascript...
even better it sets the contentContainer as the drag handle.

 

function

setMyHandleDock(dock, args)

{

  dock.set_handle(dock.get_contentContainer());

}

 

Dim

dk As New RadDock()

dk.OnClientInitialize = "setMyHandleDock"
...

 

Tags
Dock
Asked by
Adriano
Top achievements
Rank 1
Answers by
Petya
Telerik team
Adriano
Top achievements
Rank 1
Rambo the Dog
Top achievements
Rank 1
Share this question
or