How to get the control raddock ID

4 posts, 1 answers
  1. Karthik
    Karthik avatar
    18 posts
    Member since:
    Aug 2010

    Posted 05 Oct 2010 Link to this post

    Hi all,

    I am trying to load RadDock dynamically with controls on dock expand using AJAX. I have provided the code below the commented part is the problem. I am unable to get the control ID which raised the postback.

    If possible provide me with the code to dynamically create the portal page with the ajaxified docks.
    RadDock RadDock1 = new RadDock();
        RadAjaxPanel AjPanel = new RadAjaxPanel();
     
        RadDock RadDock2 = new RadDock();
        RadAjaxPanel AjPanel2 = new RadAjaxPanel();
        
        protected void Page_Init(object sender, EventArgs e)
        {
            Session["ExpandCtrlID"] = null;
     
            AjPanel.RenderMode = UpdatePanelRenderMode.Inline;
            RadDock1.ID = "RadDock1";
            DockExpandCollapseCommand ex1 = new DockExpandCollapseCommand();
     
            RadDock1.Commands.Add(ex1);
            RadDock1.Collapsed = true;
            RadDock1.Command += new DockCommandEventHandler(RadDock1_Command);
            RadDock1.ContentContainer.Controls.Add(AjPanel);
            RadDock1.CommandsAutoPostBack = true;
            RadDock1.OnClientCommand = "DockOnClientCommand";
            RadDockZone1.Controls.Add(RadDock1);
     
            AjPanel2.RenderMode = UpdatePanelRenderMode.Inline;
            RadDock2.ID = "RadDock2";
            RadDock2.Commands.Add(new DockExpandCollapseCommand());
            RadDock2.Collapsed = true;
            RadDock2.Command += new DockCommandEventHandler(RadDock2_Command);
            RadDock2.ContentContainer.Controls.Add(AjPanel2);
            RadDock2.CommandsAutoPostBack = true;
            RadDock2.OnClientCommand = "DockOnClientCommand";
            RadDockZone1.Controls.Add(RadDock2);
        }
     
     
        void RadDock2_Command(object sender, DockCommandEventArgs e)
        {
            string controlID = RadDock2.ClientID;
            LoadUserControlInDock(controlID);
        }
     
        void RadDock1_Command(object sender, DockCommandEventArgs e)
        {
            string controlID = RadDock1.ClientID;
            LoadUserControlInDock(controlID);       
        }
     
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = "";
            if (Page.IsPostBack)
            {
                if (ScriptManager1.IsInAsyncPostBack)
                {
                    //RadDock dock;
                    //dock = sender as RadDock;
                    //string id = dock.ClientID.ToString();
                    LoadUserControlInDock(id);
                    Label1.Text = "Asynchronous";
                }
                else
                {
                    Label1.Text = "Not Asynchronous";
                }
            }
            RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadDock1, AjPanel);
            }
     
        protected void LoadUserControlInDock(string contID)
        {
            Control c1 = new Control();
            c1 = this.LoadControl("WebUserControl.ascx");
     
            switch (contID)
            {
                case "RadDock1":
                    AjPanel.Controls.Clear();
                    AjPanel.Controls.Add(c1);
                    Test.Value = "Loaded";
                    break;
                case "RadDock2":
                    AjPanel2.Controls.Clear();
                    AjPanel2.Controls.Add(c1);
                    Test.Value = "Loaded";
                    break;
            }
        }
     
  2. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 08 Oct 2010 Link to this post

    Hello Karthik,

    The Page_Load method is a handler, as its name suggests, for the Page.Load event, and it is raised by the page. This means that the sender is not the control that posted the page back to the server, but the Page itself.
    For your specific scenario I would recommend using the RadDock's Command server-side event. I believe the following live demos will be of help:


    Best wishes,
    Pero
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Karthik
    Karthik avatar
    18 posts
    Member since:
    Aug 2010

    Posted 08 Oct 2010 Link to this post

    Hello Pero,

    I have used the Rad Dock's Server side event in the example. When i make any Ajax requests inside the control it won't raise the command event handler, Due to this the control disappears. What should i do to solve this problem?

    Thanks in Advance.
  5. Answer
    Pero
    Admin
    Pero avatar
    1156 posts

    Posted 12 Oct 2010 Link to this post

    Hello Karthik,

    The RadDock's Command server-side event is fired only when any of the RadDock's command buttons is pressed. It is not fired on every post back to the server.
    When dynamically adding controls you should make sure they are created and added to the page on every postback. Basically once the control is added to the dock in Command event handler, you should recreate the control in some of the Page events, like Page.Init or Page.Load. My suggestion is to do this in Page.Init, so that the ViewState is loaded correctly for this control.

    Greetings,
    Pero
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top