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

Dock Custom Statebag Updating Issue on DockPositionChanged

4 Answers 124 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 18 Jun 2007, 04:36 PM

Hello,

I'm having an issue that's related to my Dynamically loaded userctrls within a dock, but it was different enough to warrant a new thread.

It would greatly simplify things if there were a server event that would fire for the specific dock control that was moved that would have an e.NewIndex and e.OldIndex parameter values. This gives you a much finer degree of control when creating your own state bag for the dock control.

Here's the issue with NOT having that event available. For the example, I have a table like so:

tblPageContent
- PageNumber
- ObjectID (note: object id can only exist on one page, so its a unique value within this table)
- ObjectOrder

Say I have 8 docks dynamically loaded and I move one up 4 places in the layout. When I move a dock up, the following happens;
- 1. OnInit is triggered and the dynamic docks are 'refreshed'
- 2. 'Refreshing' and save process include:
    >Adding docks in Init (wired-up to DockPositionedChanged)
    >DockLoadLayout being triggered
    >DockPositionChanged event firing for each affected dock
        >> In this event a page scoped StringBuilder variable is built
              and loaded with each ObjectID(Dock ID) and Index affected
              in this event
    >DockSaveLayout is triggered
        >> If the Page level scoped StringBuilder variable is NOT nothing
              (which is only filled in the DockPositionChanged event), then
              the deliminated string of objectID's and it's new indexes
              are updated in the database table.

Notes about the above:
1. The above forces me to pass in a deliminated string of ALL affected objects wrapped in the docks AND their new indexes. So since there's no easy way of handling arrays for both SQL Server and Oracle, that means passing in a string like so to be parsed by the Stored Procedure:
"|objectid,index|objectid,index|" OR "|72,2||73,3||74,1|".
 
2. I then have a messy Oracle update statement where the objectid is parsed out of the string in the where clause and the index value is parsed out (the messy part) in the SET statement:


update tblPageContent set

object_order = SUBSTR(PageObjects_in,INSTR(PageObjects_in,'|'||TRIM(objectid)||',')+LENGTH(TRIM(objectid))+2,(INSTR(PageObjects_in,'|',INSTR(PageObjects_in,'|'||TRIM(objectid)||',')+1))-(INSTR(PageObjects_in,'|'||TRIM(objectid)||',')+LENGTH(TRIM(objectid))+2))

where INSTR(PageObjects_in,'|'||TRIM(objectid)||',') > 0;

NOTE: The SQL Server version uses CharIndexes in place of INSTR, etc.

That would be all fine and well assuming I didn't then need to write some code to handle the specific object that was moved. I have no real way of identifying the dock/object that was moved?? I only have a RANGE of affected docks/objects.

A problem that could crop up with the above object order update method is if the string get's longer than 4000 characters, I can no longer pass this into Oracle as it exceeds the Varchar2 limit (SQL Servers is 8000). This could occur if I had a long list or even a medium list with very high objectID's that would quickly eat up that 4000 character limit if I were to move an item from the bottom towards the top (as everything in between has to be updated via the DockPositionChanged method).

If I had actually done as a previous thread suggested (in the "Dynamic Dock UserCtrl Wrappers" thread) and forgone the DockPositionChanged method (to build my stringbuilder list of objects to update) and just used the SaveDockLayout method, then I would've had to build a deliminated string for EVERY single dock in that list and needlessly updated those object orders in the database (which also puts needlessly more row locks in the database table while updating).

So it's nice to have this DockPositionChanged event around, but in addition to it, could something like a 'DockPositionChanging' event be added with a parameter that has e.OldIndex and e.NewIndex. Then I can identify the specific object/dock that needs to be adjusted in the database. I can also simplify my update statements and have only 4 integer stored proc parameters (pagenumber, objectid, oldindex, newindex). It's not too hard to then write a SQL statement that would increment or decrement by 1 the 'objectorder' field for any objects 'below' or 'above' the current object.

In short - does a dock server event already exist that let's me identify the specific dock that was moved/is moving and if not, could an event be added? Again, my specific issue is that I can't identify the specific dock id (equal to objectID in my example) that was moved.

Thanks,
Chris
    

4 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 21 Jun 2007, 01:50 PM
Hello Chris,

DockPositionChanged is thrown only for the docks that have been moved and there you have information for both the new and the old index. Here is how you can get the old/new indices and the id of the moved dock:

protected void RadDock1_DockPositionChanged(object sender, Telerik.Web.UI.DockPositionChangedEventArgs e)
    {
        int oldIndex = ((RadDock)sender).Index;
        int newIndex = e.Index;
        string dockID = ((RadDock)sender).ID;
    }

If I missed anything in your question as it was a long post, please let me know and we will do our best to answer it.

Best wishes,
Petya
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Chris
Top achievements
Rank 1
answered on 22 Jun 2007, 01:01 PM
Petya,

Per my other thread, I'd like to send a simply code example which would clearly show what I'm trying to achieve.

For this moving issue, what you've described would still give me a NewIndex and OldIndex for 'all affected' docks. Because when you move a dock - for instance say I have 4 docks loaded and I drag the bottom one to the top, DockPositionedChanged will be triggered 4 times for each of those 4 docks that were affected. What I'm looking for is to determine which single dock I clicked and dragged with the mouse and then retrieve it's OldIndex and NewIndex.

As I mentioned in my other thread, I'd like to just take you up your offer and send you a simplified code example. How would I go about sending you that attachment?

Thanks!
Chris
0
Petya
Telerik team
answered on 22 Jun 2007, 01:07 PM
Hello Chris,

In your other ticket thread I explained how you can send us your code. As for the DockPositionChanged  - it will be raised only for the dock that was moved. In your example with the 4 docks - if you move the one at the bottom to become at the top - DockPositionChanged will be raised only for this dock, not for all four docks.

Greetings,
Petya
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Chris
Top achievements
Rank 1
answered on 22 Jun 2007, 01:51 PM
Petya,

I got the instructions on how to upload in your response to the other thread, so I'll go ahead and get that to you later this morning. Back to DockPositionChanged. In my code, it fires for every single one of the affected docks. Strange. These again are dynamically loaded docks and for each one I load I wire-up the dockpositionchanged event (because if I don't, it won't fire at all). Like so for vb:

AddHandler dock.DockPositionChanged, AddressOf dock_DockPositionChanged


This will also be demonstrated in the example code I'm sending, so I'll hold off anymore questions until you've had a chance to look at it.

Thanks!
Chris
Tags
Dock
Asked by
Chris
Top achievements
Rank 1
Answers by
Petya
Telerik team
Chris
Top achievements
Rank 1
Share this question
or