Postback not firing custom command

3 posts, 1 answers
  1. Atiq Ur Rehman
    Atiq Ur Rehman avatar
    66 posts
    Member since:
    Jul 2004

    Posted 22 Jul 2008 Link to this post

    Hi guys,

    I am stuck with something here. Basically I wanted a delete button for my docks, so I implemented the dock custom command which when user clicks firs the command and deletes the dock. I also needed confirmation on it so I implemented confirmation for client side. The only problem now is that I have to check something else as well before I delete the dock, so I have this database procedure which checks and returns more then 0 if there is something, then I show an error message saying that user needs to delete that thing before they can delete dock, but my custom command doesn't fire the postback although I have got postback enabled. Is there anyway to ajaxify this thing so that user see the error message which I want to show? Here is the code;

    here is the code file;
            Protected Sub Page_Init(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Init  
            End Sub 
        Sub createDocks()  
                    Dim dr As IDataReader = "Calling from the database here" 
                    While dr.Read()  
                        Dim aDock As New RadDock()  
                        aDock.DockMode = DockMode.Docked  
                        aDock.UniqueName = Guid.NewGuid().ToString()  
                        aDock.ID = CStr(dr.Item("ID"))  
                        aDock.Title = CStr(dr.Item("Title"))  
                        Dim custCMD As New DockCommand()  
                        custCMD.Name = "deleteCMD" 
                        custCMD.CssClass = "pullImage" 
                        custCMD.Text = "Delete" 
                        custCMD.AutoPostBack = True 
                        custCMD.OnClientCommand = "CustomCommand" 
                        AddHandler aDock.Command, AddressOf dock_Command  
                        aDock.DefaultCommands = Dock.DefaultCommands.None  
                        Dim triger As New AsyncPostBackTrigger()  
                        triger.ControlID = aDock.ID  
                        triger.EventName = "DockPositionChanged" 
                    End While 
                Catch ex As Exception  
                    Dim exp As New exHandle  
                    lblmsg.Text = exp.processExp(ex, "", Now)  
                End Try 
            End Sub 
          Sub dock_Command(ByVal sender As ObjectByVal e As DockCommandEventArgs)  
                If Session("ClassID"Is Nothing Then 
                    mainPNL.Visible = False 
                    notAllowed.Visible = True 
                    If e.Command.Name = "deleteCMD" Then 
                        Dim aDock As RadDock = sender  
                        Dim ID_int As Integer = aDock.ID  
                        Dim ClassID As Integer = CInt(Session("ClassID"))  
                        Dim SetsCount As Integer = "Calling from database to check if there is anything" 
                        If (SetsCount > 0) Then 
                            lblmsg.Text = "<BR>There are " & SetsCount & " in this section. Please delete them first." 
                            'delete from database here and release session  
                            ScriptManager.RegisterStartupScript(uPanel, Me.[GetType](), "RemoveDock"String.Format("function _removeDock() {{" & Chr(13) & "" & Chr(10) & "" & Chr(9) & "Sys.Application.remove_load(_removeDock);" & Chr(13) & "" & Chr(10) & "" & Chr(9) & "$find('{0}').undock();" & Chr(13) & "" & Chr(10) & "" & Chr(9) & "$get('{1}').appendChild($get('{0}'));" & Chr(13) & "" & Chr(10) & "" & Chr(9) & "$find('{0}').doPostBack('DockPositionChanged');" & Chr(13) & "" & Chr(10) & "}};" & Chr(13) & "" & Chr(10) & "Sys.Application.add_load(_removeDock);", (DirectCast(sender, RadDock)).ClientID, uPanel.ClientID), True)  
                        End If 
                    End If 
                End If 
            End Sub 

    here is the aspx file;
        <asp:ScriptManager id="ScriptManager" runat="server"/>    
             <radT:radformdecorator id="FormDecorator1" runat="server" decoratedcontrols="all" 
      <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div> 
         <script type="text/javascript">  
            function GetRadWindow()  
                var oWindow = null;  
                if (window.radWindow) oWindow = window.radWindow;  
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;  
                return oWindow;  
            function returnToParent()  
                var oWnd = GetRadWindow();  
            function CustomCommand(dock, args)  
                //You can implement your custom logic in this method  
                if (!confirm("Are you sure you want to delete this section?"))  
                <table width="100%" id="notAllowed" runat="server">  
        <td>You don't have permission to view this page. Please contact support.<br /> 
        <input id="Button1" onclick="returnToParent(); return false;" type="button"   
                    value="Close" class="button" /></td>  
           <asp:Panel runat="server" ID="mainPNL" Width="500">   
    <table cellpadding="0" cellspacing="0" border="0" width="100%">  
    Select a section and drag it up and down to change its order.  
    <asp:Label ID="lblmsg" runat="server" Font-Bold="True"   
           <radT:raddocklayout runat="server" id="rdLayout" Skin="Sunset">  
                <radT:raddockzone runat="server" id="rdZone" Width="100%" Skin="Sunset">  
                <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="uPanel">  
    <td><br /> 
    <input id="closeBTN" onclick="returnToParent(); return false;" type="button"   
                    value="Exit" class="button" /> 
    <%--                <asp:Button ID="exitBTN" runat="server" Text="Exit" Width="130px"   
                        CausesValidation="False" />--%> 
                         &nbsp;&nbsp;<asp:Button ID="resetBTN" runat="server"   
            CausesValidation="False" Text="Reset" Width="130px" /> 
                         <asp:Button ID="submitBTN" runat="server" Text="Save & Exit" Width="130px"   
                        CausesValidation="False" /> 

  2. Atiq Ur Rehman
    Atiq Ur Rehman avatar
    66 posts
    Member since:
    Jul 2004

    Posted 22 Jul 2008 Link to this post

    Also I forgot one thing.

    I have a reset button as well which should reset all the docks where they were before. What would be the best approach to do that? call the createDocks() but that doesn't work? can someone please help.

  3. Answer
    Sophy avatar
    636 posts

    Posted 24 Jul 2008 Link to this post

    Hi Atiq,

    I prepared a sample page based on the code snippets you have sent us and commented some lines which needed missing resources. However, I was not able to reproduce the problem with command event handler not being fired. Running the page on my side the command event handler was fired but the message you mention was not displayed. That is why, I placed the label whose text is updated in the command event handler inside an UpdatePanel and this solved the problem. I have attached my test page which demonstrates how to fix the described issue.
    Regarding your other question about the reset button you will need to save the old state in a Cookie, in the Session or in database depending on the requirements of your exact scenario. Then at reset button click apply the correct state in a way similar to the one
    demonstrated in the RadDockLayout1_LoadDockLayout method in the Dynamically Created Docks online example, e.g.:
    Private Sub SetPositions()   
        Dim positions As New Dictionary(Of StringString)()   
        Dim indices As New Dictionary(Of StringInteger)()   
        For Each state As DockState In OldDockStates   
            positions(state.UniqueName) = state.DockZoneID   
            indices(state.UniqueName) = state.Index   
        RadDockLayout1.SetRegisteredDockParents(positions, indices)   
    End Sub  

    In case the above suggestion cannot help you solve the problems, please, open a support ticket and attach a simple running application which demonstrates your scenario and reproduces the problems you experience. We will take a closer look at your code, test it on our side, investigate the issues and do our best to help you. For your convenience I have attached a screenshot with instructions how to open a support ticket.

    Best regards,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top