Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Docking > custom dock command postback issue
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered custom dock command postback issue

Feed from this thread
  • dipan avatar

    Posted on Dec 15, 2010 (permalink)

    Hi,
    I have put a usercontrol name called Content where I have used radtoolber and put into a raddock zone. I am trying to edit the contents using custom dock command. The problem I am having is popup coming but after certain time its getting postback. So can anyone please help me to stop the post back. please see below the code snippet.
    Thanks.
    UserControl:
    <telerik:RadDockZone ID="RadDockZone1" runat="server" Orientation="Vertical" Width="560px" MinHeight="400px">
    <telerik:RadDock ID="RadDock2" runat="server" Title="Content" Width="250px" EnableAnimation="true" EnableRoundedCorners="true" Resizable="true" OnCommand="RadDock_Command"  AutoPostBack="true">
     <Commands>
     <telerik:DockCloseCommand />
       <telerik:DockCommand AutoPostBack="true" Name="Custom Command" OnClientCommand="CustomCommand" />
      </Commands>
      <ContentTemplate>               
      <cms:StaticHTML id="StaticHTML1" runat="server"></cms:StaticHTML>
      </ContentTemplate>
      </telerik:RadDock>
     </telerik:RadDockZone>
     
    Script:
    <script type="text/javascript">
        function CustomCommand() {
          OpenPopup('Edit Content', '../../Modules/Content/ContentEdit.aspx', 700, 500);return true;
                  
               }
            }
        </script>

  • Pero Pero admin's avatar

    Posted on Dec 15, 2010 (permalink)

    Hi Dipan,

    Could you please provide a fully working sample project that demonstrates the issue? I tested your code locally, but didn't experience the problems. Here is the full source code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="RadScriptManager1" runat="server">
        </asp:ScriptManager>
        <script type="text/javascript">
            function CustomCommand(dock, args)
            {
                open("http://www.telerik.com", "Telerik");
            }
        </script>
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <telerik:RadDockLayout ID="RadDockLayout1" runat="server">
            <telerik:RadDockZone ID="RadDockZone2" runat="server" Orientation="Vertical" Width="560px"
                MinHeight="400px">
                <telerik:RadDock ID="RadDock2" runat="server" Title="Content" Width="250px" EnableAnimation="true"
                    EnableRoundedCorners="true" Resizable="true" AutoPostBack="true">
                    <Commands>
                        <telerik:DockCloseCommand />
                        <telerik:DockCommand AutoPostBack="true" Name="Custom Command" OnClientCommand="CustomCommand" />
                    </Commands>
                    <ContentTemplate>
                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eu leo quis felis eleifend
                        congue id ac nulla. Suspendisse in sapien eu tortor aliquam luctus. Suspendisse
                        pretium, nulla sit amet porttitor lobortis, ante sapien blandit ante, et tempor
                        magna eros nec sapien. In hac habitasse platea dictumst. Nullam a quam lorem, eu
                        vestibulum turpis. Praesent a neque et diam tincidunt suscipit ut semper massa.
                        Vivamus posuere, mi eu consectetur consequat, libero risus accumsan erat, ut facilisis
                        dolor justo a enim. Donec suscipit tincidunt lorem, sed aliquam velit pulvinar euismod.
                        Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus
                        mus.
                    </ContentTemplate>
                </telerik:RadDock>
            </telerik:RadDockZone>
        </telerik:RadDockLayout>
        </form>
    </body>
    </html>

    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    using System.Data;
    using System.Configuration;
    using System.Web.Security;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Telerik.Web.UI;
    using System.Drawing;
     
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                Label1.Text = "Postback occured at: " + DateTime.Now.ToString();
            }
        }
    }

    Best wishes,
    Pero
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  • dipan avatar

    Posted on Dec 15, 2010 (permalink)

    Hi Pero,
    Thanks for you reply. I have figured it out.  I had to remove the autoPostback=true property as I was calling OnClient event. I have one more question like is there have anyway to access command property from my custom base class. What I am trying to do is I have a template which consists of RadDockzone and I will dynamically add all module(ascx). I was doing before with webparts and in code behind I can access the webpart verb and add a new custom verb for example in content section there will be edit verb where I will pass content id and call popup get the contents from database. To get access of webpart verb I had to implement webpart IWebActionable interface.  So just wondering if possible like this with reddock command.
    I am building a CMS where requirement is admin will have flexibility to manage contents with drag and drop. So I was started using Webparts then after I have found Telerek Raddock does almost same things with nice visual interface. So I am now moving it to apply telerik Raddock. One more thing the Telerik  DockHandle property I want to make it true only in Admin and all others should not be drag and drop facility. So if you have any demo page then it will really help me a lot.
     One more issue in aspx or ascx page telerik intellicense is not coming.
    please see the below code which one I have done with webparts. So if something like available with telerik dock command......

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Castle.Windsor;
    using CMSEngine.Core;
    using CMSEngine.Core.Domain;
    using CMSEngine.Web.Util;
    using CMSEngine.Web.UI;
    using CMSEngine.Core.Service.SiteStructure;
    using CMSEngine.Core.Service.Membership;
     
    namespace CMSEngine.Web.Modules.Content
    {
        public partial class Content : System.Web.UI.UserControl,IWebPart,IWebActionable
        {
            private IDocumentService _documentService;
            private IWindsorContainer _container;
            private string actionLink = "";
            public long DocumentID
            {
                get
                {
                    long result = 0;
                    if (ViewState["documentID"] != null)
                    {
                        result = long.Parse(ViewState["documentID"].ToString());
                    }
                    return result;
                }
                set
                {
                    ViewState["documentID"] = value;
                }
            }
     
            #region IWebPrt Properties
     
            /// <summary>
            /// set Title of webpart control
            /// </summary>
            protected string _title = "[Generic Title]";
            public string Title
            {
                get { return _title; }
                set { _title = value; }
            }
     
            /// <summary>
            /// set Subtitle of webpart control
            /// </summary>
            protected string _subTitle = "";
            public string Subtitle
            {
                get { return _subTitle; }
                set { _subTitle = value; }
            }
     
            /// <summary>
            /// set Caption of webpart control
            /// </summary>
            protected string _caption = "";
            public string Caption
            {
                get { return _caption; }
                set { _caption = value; }
            }
     
            /// <summary>
            /// set Description of webpart control
            /// </summary>
            private string _description = "";
            public string Description
            {
                get { return _description; }
                set { _description = value; }
            }
     
            /// <summary>
            /// set TitleUrl of webpart control
            /// </summary>
            private string _titleUrl = "";
            public string TitleUrl
            {
                get { return _titleUrl; }
                set { _titleUrl = value; }
            }
     
            /// <summary>
            /// set TitleIconImageUrl of webpart control
            /// </summary>
            private string _titleIconImageUrl = "";
            public string TitleIconImageUrl
            {
                get { return _titleIconImageUrl; }
                set { _titleIconImageUrl = value; }
            }
     
            /// <summary>
            /// set Title of webpart control
            /// </summary>
            private string _catalogIconImageUrl = "";
            public string CatalogIconImageUrl
            {
                get { return _catalogIconImageUrl; }
                set { _catalogIconImageUrl = value; }
            }
     
            #endregion
     
            //implement the IWebActionable interface to add Edit and Section setting verbs
            #region IWebActionable
     
            private WebPartVerbCollection m_Verbs;
            // This property implements the IWebActionable interface.
            WebPartVerbCollection IWebActionable.Verbs
            {
                get
                {
                    if (m_Verbs == null)
                    {
                        User cmsEngineUser = this.Page.User.Identity as User;
     
                        ArrayList verbsList = new ArrayList();
     
     
                        
                        WebPartVerb editVerb = new WebPartVerb("editVerb", actionLink);
                        editVerb.Text = "Edit";
                        editVerb.Description = "Edit";
                        editVerb.Visible = true;
                        editVerb.Enabled = true;
                        verbsList.Add(editVerb);
     
     
                        m_Verbs = new WebPartVerbCollection(verbsList);
                        return m_Verbs;
                    }
                    return m_Verbs;
                }
            }
            #endregion
     
            public Content()
            {
                this.Title = "Content";
                
            }
     
            protected void Page_Load(object sender, EventArgs e)
            {
                DocumentID = 2;
                InitialzePage();
                
            }
     
            private void InitialzePage()
            {
                this._container = ContainerAccessorUtil.GetContainer();
     
                this._documentService = _container.Resolve<IDocumentService>();
     
                Document document = this._documentService.GetById(DocumentID);
     
                Literal htmlControl = new Literal();
                 
     
                if (document != null)
                {
                    htmlControl.Text = document.Content;
                    this.Title = document.Title;
                     
                    actionLink = string.Format("OpenPopup('Edit Content', '../../Modules/Content/ContentEdit.aspx', 700, 500); return false;");
                }
                else
                {
                               
                    actionLink = string.Format("OpenPopup('Edit Content', '../../Modules/Content/ContentEdit.aspx', 700, 500); return false;");
                }
                 
                this.plcContent.Controls.Add(htmlControl);
     
            }
     
     
        }
    }

    Thanks.

  • Pero Pero admin's avatar

    Posted on Dec 16, 2010 (permalink)

    Hi Dipan,

    If you can get a reference to the RadDock inside your code behind, you can get a reference to the command was pressed. Is the module (the user control) added to the RadDock control? If yes then the following method will get a reference to the parent dock control:
    /// <summary>
    /// Returns a reference to a parent dock control
    /// </summary>
    /// <param name="ctrl">The control that is added to the control.</param>
    /// <returns>The RadDock reference</returns>
    private RadDock GetDock(Control ctrl)
    {
        Control parent = ctrl.Parent;
        while (parent != null)
        {
            if (parent is RadDock)
                break;
            parent = parent.Parent;
        }
        return parent as RadDock;
    }

    RadDock.Commands gets a reference to the collection of all commands that are currently added to the RadDock control.

    We don't have an example that shows the requested functionality, but I guess it could be easily achieved using the IsInRole method to check whether the currently logged user belongs the the admin group, and then disable/enable the dragging of the docks (Page.User.IsInRole("admins")).

    I am not sure why the intellisense of the Telerik controls is not working in the .ascx and the .aspx. Could you please check whether you have referenced the correct Telerik.Web.Design DLL? The version of the Telerik.Web.Design.dll should be the same as the Telerik.Web.UI.dll. If you do not reference the Design dll, please check whether you reference the Telerik.Web.UI.dll at all.

    All the best,
    Pero
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  • dipan avatar

    Posted on Dec 16, 2010 (permalink)

    Hi Pero,
    Thanks for your reply. I am trying to call a javascript function from codebehind when the custom command will be click. please see my code below which is not working.
    private RadDock CreateRadDock()
            {
                int docksCount = CurrentDockStates.Count;
                RadDock dock = new RadDock();
                dock.DockMode = DockMode.Docked;
                dock.UniqueName = Guid.NewGuid().ToString().Replace("-", "a");
                dock.ID = string.Format("RadDock{0}",dock.UniqueName);
                dock.Title = "Dock";
                dock.Text = string.Format("Added at {0}", DateTime.Now);
                dock.Commands.Add(new DockCloseCommand());
                dock.Commands.Add(new DockExpandCollapseCommand());
                dock.Commands.Add(new DockCommand());
                dock.Command += new DockCommandEventHandler(dock_Command);
                //dock.CommandsAutoPostBack = true;
                 
     
                return dock;
            }
     
    public void dock_Command(object sender, DockCommandEventArgs e)
            {
                //ScriptManager.RegisterStartupScript(this, this.GetType(), "Edit Content", "alert('hi');", true);
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Edit Content", "OpenPopup('Edit Content', '../../Modules/Content/ContentEdit.aspx', 700, 500); ", true);
            }
     
      protected void ButtonAddDock_Click(object sender, EventArgs e)
            {
                RadDock dock = CreateRadDock();
                //find the target zone and add the new dock there
                RadDockZone dz = (RadDockZone)FindControl(DropDownZone.SelectedItem.Text);
                dz.Controls.Add(dock);
                CreateSaveStateTrigger(dock);
     
                //Load the selected widget in the RadDock control
                dock.Tag = DropDownWidget.SelectedValue;
                LoadWidget(dock);
            }

    I want to call javascript function which will popup. Please help would be really appreciated.
    PS: If I call OnClientCommand then its works. But in my case I am require to pass querystring in my OpenPopUp function dynamically for example
    string.Format("OpenPopup('Edit Content', '../../Modules/Content/ContentEdit.aspx?NodeID={0}', 700, 500); ", NodeID);

    Thanks.

  • dipan avatar

    Posted on Dec 20, 2010 (permalink)

    Hi Pero,
    Can you please help me with the previous post queries. Thanks.

  • Pero Pero admin's avatar

    Posted on Dec 21, 2010 (permalink)

    Hello Dipan,

    For your convenience I have implemented a sample project that renders a script from the server when the ExpandCollapse command is pressed, and opens a new window. Here is the full source code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="RadScriptManager1" runat="server">
        </asp:ScriptManager>
        <script type="text/javascript">
            function OpenPopUp(url, title)
            {
                open(url, title);
            }
        </script>
        <div>
            <telerik:RadDockLayout ID="RadDockLayout1" runat="server">
                <telerik:RadDockZone ID="RadDockZone1" runat="server" MinHeight="300px" Width="300px">
                    <telerik:RadDock ID="RadDock1" runat="server" Title="RadDock-Title" Width="300px"
                        CommandsAutoPostBack="true" Height="300px">
                        <ContentTemplate>
                            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eu leo quis felis eleifend
                            congue id ac nulla. Suspendisse in sapien eu tortor aliquam luctus. Suspendisse
                            pretium, nulla sit amet porttitor lobortis, ante sapien blandit ante, et tempor
                            magna eros nec sapien. In hac habitasse platea dictumst. Nullam a quam lorem, eu
                            vestibulum turpis. Praesent a neque et diam tincidunt suscipit ut semper massa.
                            Vivamus posuere, mi eu consectetur consequat, libero risus accumsan erat, ut facilisis
                            dolor justo a enim. Donec suscipit tincidunt lorem, sed aliquam velit pulvinar euismod.
                            Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus
                            mus.
                        </ContentTemplate>
                    </telerik:RadDock>
                </telerik:RadDockZone>
            </telerik:RadDockLayout>
        </div>
        </form>
    </body>
    </html>

    using System;
    using Telerik.Web.UI;
     
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            RadDock1.Command += new DockCommandEventHandler(RadDock1_Command);
        }
     
        void RadDock1_Command(object sender, DockCommandEventArgs e)
        {
            if (e.Command.Name == "ExpandCollapse")
            {
                string script = string.Format(
                                @"function onLoad()
                                {{
                                    OpenPopUp('{0}','{1}');
                                    Sys.Application.remove_load(onLoad);
                                }}
                                Sys.Application.add_load(onLoad);"
                                , "http://www.telerik.com", "TELERIK");
                RadScriptManager.RegisterStartupScript(RadDock1, typeof(RadDock), "key", script, true);
            }
        }
    }


    Kind regards,
    Pero
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Docking > custom dock command postback issue