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

A Control With ID '' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.

4 Answers 629 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Tanuj
Top achievements
Rank 1
Tanuj asked on 18 Sep 2008, 04:03 AM
i am dynamically creating RadDocks from an Array for the 1st time and then using the loaded docks i want to save them in the database for per user basis.

i also have a update panel for the "DockPositionChanged" event, however this is giving the following error.

A control with ID 'RadDockf49937fe-b13d-4730-b098-d252bb02fc45' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.

please advise..

here is the source code
        <telerik:raddocklayout runat="server" id="RadDockLayout1"   
            onsavedocklayout="RadDockLayout1_SaveDockLayout" 
            onloaddocklayout="RadDockLayout1_LoadDockLayout">  
        <table cellspacing="5" cellpadding="5" border="0" width="690">            
            <tr> 
                <td> 
                    <telerik:RadDockZone ID="RadDockZone1" runat="server" Width="330px" MinHeight="243px" MinWidth="330px">  
                    </telerik:RadDockZone>                
                </td> 
                <td> 
                    <telerik:RadDockZone ID="RadDockZone2" runat="server" Width="330px" MinHeight="243px" MinWidth="330px">  
                    </telerik:RadDockZone>                
                </td> 
            </tr> 
            <tr> 
                <td colspan="2">  
                    <div style="display:none">  
                        Hidden UpdatePanel, which is used to receive the new dock controls.   
                        We will move them with script to the desired initial dock zone.  
                        <asp:updatepanel runat="server" id="UpdatePanel1">  
                        </asp:updatepanel> 
                    </div>                
                </td> 
            </tr> 
        </table> 
        </telerik:raddocklayout> 

using System;  
using System.Collections;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.Web;  
using System.Web.SessionState;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.HtmlControls;  
using Telerik.Web.UI;  
using System.Data.SqlClient;  
using System.Configuration;  
using System.Text;  
 
public partial class Portal : System.Web.UI.Page  
{  
    private SqlConnection _conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DockConnectionString"].ConnectionString);  
    private int _count = 0;  
    bool LoadDefaults = true;  
    protected void Page_Init(object sender, EventArgs e)  
    {  
        LoadDefaults=true;  
        if (LoadDefaults)  
            LoadDefaultsFromSharePoint();  
        else  
            LoadFromDatabase();  
    }  
 
    private void LoadDefaultsFromSharePoint()  
    {  
        string[] WidgetTitles = { "ECAMPAIGNS","NEWS","MY LISTINGS","MY CALENDAR"};  
        string[] WidgetControls = { "HP_eCampaign.ascx", "HP_News.ascx", "HP_Listings.ascx", "HP_Calendar.ascx"};  
        //Recreate the docks in order to ensure their proper operation  
        bool isZoneOne=true;  
        int i = 0;  
        foreach (string widget in WidgetTitles)  
        {  
            RadDock dock = CreateRadDock(widget, WidgetControls[i]);   
                //We will just add the RadDock control to the RadDockLayout.  
                // You could use any other control for that purpose, just ensure  
                // that it is inside the RadDockLayout control.  
                // The RadDockLayout control will automatically move the RadDock  
                // controls to their corresponding zone in the LoadDockLayout  
                // event (see below).  
                if (isZoneOne)  
                {  
                    isZoneOne=false;  
                    RadDockZone1.Docks.Add(dock);    
                }  
                else  
                {  
                    isZoneOne=true;  
                    RadDockZone2.Docks.Add(dock);  
                }  
                //We want to save the dock state every time a dock is moved.  
                CreateSaveStateTrigger(dock);  
                i++;  
        }  
    }  
 
    private void LoadFromDatabase()  
    {  
        string dockState = "";  
        try  
        {  
            _conn.Open();  
            SqlCommand command = new SqlCommand("select State from States where id=1", _conn);  
            dockState = command.ExecuteScalar().ToString();  
            _conn.Close();  
        }  
        catch  
        {  
        }  
 
        string[] currentDockStates = dockState.Split('|');  
        _count = currentDockStates.Length;  
 
        //Recreate the docks in order to ensure their proper operation  
        for (int i = 0; i < _count; i++)  
        {  
            if (currentDockStates[i].Trim() != string.Empty)  
            {  
                RadDock dock = CreateRadDockFromState(currentDockStates[i]);  
                //We will just add the RadDock control to the RadDockLayout.  
                // You could use any other control for that purpose, just ensure  
                // that it is inside the RadDockLayout control.  
                // The RadDockLayout control will automatically move the RadDock  
                // controls to their corresponding zone in the LoadDockLayout  
                // event (see below).  
                RadDockLayout1.Controls.Add(dock);  
                //We want to save the dock state every time a dock is moved.  
                CreateSaveStateTrigger(dock);  
            }  
        }  
    }  
    protected void Page_Load(object sender, EventArgs e)  
    {  
 
    }  
 
    private RadDock CreateRadDockFromState(string stringState)  
    {  
        System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();  
        DockState state = serializer.Deserialize<DockState>(stringState);  
        RadDock dock = new RadDock();  
        dock.ID = string.Format("RadDock{0}", state.UniqueName);  
        dock.ApplyState(state);  
        return dock;  
    }  
 
    private RadDock CreateRadDock(string WidgetTitle, string WidgetControlName)  
    {  
        RadDock dock = new RadDock();  
        dock.UniqueName = Guid.NewGuid().ToString();  
        dock.ID = string.Format("RadDock{0}", dock.UniqueName);  
        dock.Title = WidgetTitle;  
        dock.Width = Unit.Pixel(330);  
        dock.Height = Unit.Pixel(243);  
        try  
        {  
            Control widget = LoadControl(WidgetControlName);  
        }  
        catch (Exception ex)  
        {  
            dock.Text = string.Format("Error in Widget: {0}", ex.Message);  
        }  
    
        //dock.DefaultCommands=          
        return dock;  
    }  
 
    private void CreateSaveStateTrigger(RadDock dock)  
    {  
        //Ensure that the RadDock control will initiate postback  
        // when its position changes on the client or any of the commands is clicked.  
        //Using the trigger we will "ajaxify" that postback.  
        dock.AutoPostBack = true;  
        dock.CommandsAutoPostBack = true;  
 
        AsyncPostBackTrigger saveStateTrigger = new AsyncPostBackTrigger();  
        saveStateTrigger.ControlID = dock.ID;  
        saveStateTrigger.EventName = "DockPositionChanged";  
        UpdatePanel1.Triggers.Add(saveStateTrigger);  
    }  
 
 
 
    protected void RadDockLayout1_SaveDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e)  
    {  
        string dockState;  
        System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();  
        List<DockState> stateList = RadDockLayout1.GetRegisteredDocksState();  
        StringBuilder serializedList = new StringBuilder();  
        int i = 0;  
        while (i < stateList.Count)  
        {  
            serializedList.Append(serializer.Serialize(stateList[i]));  
            serializedList.Append("|");  
            i++;  
        }  
        dockState = serializedList.ToString();  
        if (dockState.Trim() != String.Empty)  
        {  
            try  
            {  
                _conn.Open();  
                SqlCommand command = new SqlCommand(String.Format("update States set State='{0}' where id=1", dockState), _conn);  
                command.ExecuteNonQuery();  
                _conn.Close();  
            }  
            catch  
            {  
            }  
        }  
 
        //Save the dockState string into DB        
    }  
 
    protected void RadDockLayout1_LoadDockLayout(object sender, Telerik.Web.UI.DockLayoutEventArgs e)  
    {  
        if (!LoadDefaults) // Perform this task only when not loading defaults,I.E when reading from database  
        {  
            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();  
            //Get saved state string from the database - set it to dockState variable for example   
            string dockState = "";  
            try  
            {  
 
                _conn.Open();  
                SqlCommand command = new SqlCommand("select State from States where id=1", _conn);  
                dockState = command.ExecuteScalar().ToString();  
                _conn.Close();  
            }  
            catch  
            {  
            }  
 
            string[] currentDockStates = dockState.Split('|');  
            foreach (string stringState in currentDockStates)  
            {  
                if (stringState.Trim() != string.Empty)  
                {  
                    DockState state = serializer.Deserialize<DockState>(stringState);  
                    e.Positions[state.UniqueName] = state.DockZoneID;  
                    e.Indices[state.UniqueName] = state.Index;  
                }  
            }  
        }  
    }  
}  
 


4 Answers, 1 is accepted

Sort by
0
Tanuj
Top achievements
Rank 1
answered on 18 Sep 2008, 04:26 AM
also, do you have any example that shows how to

(1) dynamically create docks for a user for the very first time (no database entry exist yet)

(2) add custom titles and custom ID instead of Unique ID
0
Sophy
Telerik team
answered on 19 Sep 2008, 01:48 PM
Hi Tanuj,

Thank you for the provided code.

I was able to reproduce the problem you experience with the code you have sent us. After reviewing it I noticed that you use the Docks collection of the RadDockZone to add docks in it. Adding the docks in the Docks collection does not add the docks inside the Controls collection of the zone which leads to the error you observe. The Docks collection represents the docks added in the zone but it cannot be used for adding the docks in the zone. What is more, if you add a dock to the Controls collection of a zone it will automatically be added to its Docks collection. That is why, to solve the problem you experience you should simply replace the line 
    zoneControl.Docks.Add(dock);

with the following one 
    zoneControl.Controls.Add(dock);

in the CreateRadDock method.


I was not able to understand completely the questions you are asking in the second post. Please, explain in more details what you mean under "dynamically create docks for a user for the very first time". Doesn't the CreateRadDock method from the Dynamically Created Docks online example answer your requirements? What is different in your case? What do you have in mind under custom titles and Custom ID? You can set the dock's title using the Title property of the control. The id of the dock can also be set using its ID property. The id can be set to any value which is unique on the page (no other control has the same id).

All the best,
Sophy
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Tanuj
Top achievements
Rank 1
answered on 19 Sep 2008, 02:06 PM
sophy,

thanks for the reply,

the online example assumes that there is an entry in the database for the user, let say the the user is a new registrant, then the example will not work as there is no dock state for this user.

hope this clarifies.

thanks in advance
0
Sophy
Telerik team
answered on 23 Sep 2008, 01:26 PM
Hello Tanuj,

It depends on the requirements of your exact scenario what will be the behavior of the example when the user is newly registered and there is no dock state for him. You could create a new database entry and create docks for the new user or simply do not create any docks if there is still no dock state for this user. It's up to you what approach you will choose. In case you experience difficulties with the implementation of your scenario, please, explain in details what is the exact scenario you want to achieve and what is the behavior you expect so that we can give you most accurate suggestion to the requirements you have. 

Best wishes,
Sophy
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Dock
Asked by
Tanuj
Top achievements
Rank 1
Answers by
Tanuj
Top achievements
Rank 1
Sophy
Telerik team
Share this question
or