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

Radconfirm instead of args.set_cancel(!confirm('Delete all selected customers?'))

2 Answers 211 Views
Window
This is a migrated thread and some comments may be shown as answers.
GlenB
Top achievements
Rank 1
GlenB asked on 19 May 2010, 04:10 AM
I would like to replace args.set_cancel(!confirm('Delete all selected customers?')) as in the example located at http://demos.telerik.com/aspnet-ajax/toolbar/examples/applicationscenarios/gridcommanditem/defaultcs.aspx?product=toolbar with a radconfirm window. I have spent hours trying different methods to achieve this and have run out of ideas.

I am using a radtoolbar as a radgrid commanditem and my code is as follows:

Javascript:
            function onToolBarClientButtonClicking(sender, args) { 
                var button = args.get_item(); 
                if (button.get_commandName() == "DeleteSelected") { 
                    if (document.getElementById('hdn_Hosp').value) { 
                    args.set_cancel(!confirm('Delete ' + document.getElementById('hdn_Hosp').value + '?')); 
                    } 
                } 
            } 
 

ASPX:
    <form id="form1" runat="server"
    <asp:HiddenField ID="hdn_Hosp" runat="server" /> 
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
    </telerik:RadScriptManager> 
    <telerik:RadFormDecorator ID="FormDecorator1" runat="server" DecoratedControls="all"
    </telerik:RadFormDecorator> 
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server"
    </telerik:RadWindowManager> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadGrid_Hospitals"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid_Hospitals" /> 
                    <telerik:AjaxUpdatedControl ControlID="hdn_Hosp" /> 
                    <telerik:AjaxUpdatedControl ControlID="RadToolBar_HospitalCMD" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="btnSubmit"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="btnSubmit" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <div> 
        <asp:SqlDataSource ID="ds_Hospitals" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            DeleteCommand="DELETE FROM [Sub_Hospitals] WHERE [HospID] = @HospID" InsertCommand="INSERT INTO [Sub_Hospitals] ([UserID], [Hospitalname]) VALUES (@UserID, @Hospitalname)" 
            SelectCommand="SELECT * FROM [Sub_Hospitals] WHERE ([UserID] = @UserID) ORDER BY [Hospitalname]" 
            UpdateCommand="UPDATE [Sub_Hospitals] SET [UserID] = @UserID, [Hospitalname] = @Hospitalname WHERE [HospID] = @HospID"
            <SelectParameters> 
                <asp:CookieParameter CookieName="UserID" Name="UserID" Type="Int32" /> 
            </SelectParameters> 
            <DeleteParameters> 
                <asp:Parameter Name="HospID" Type="Int32" /> 
            </DeleteParameters> 
            <UpdateParameters> 
                <asp:Parameter Name="UserID" Type="Int32" /> 
                <asp:Parameter Name="Hospitalname" Type="String" /> 
                <asp:Parameter Name="HospID" Type="Int32" /> 
            </UpdateParameters> 
            <InsertParameters> 
                <asp:CookieParameter CookieName="UserID" Name="UserID" Type="Int32" /> 
                <asp:Parameter Name="Hospitalname" Type="String" /> 
            </InsertParameters> 
        </asp:SqlDataSource> 
        <asp:Panel ID="pnlhosplist" runat="server" CssClass="pnlmodallist"
            <table class="tblmodallist"
                <tr> 
                    <td class="tblmodallistheading_hosp"
                        &nbsp; 
                    </td> 
                </tr> 
                <tr> 
                    <td> 
                        <asp:Panel ID="pnlHospChoices" runat="server" ScrollBars="Vertical" CssClass="pnlModalChoices"
                            <telerik:RadGrid ID="RadGrid_Hospitals" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" 
                                DataSourceID="ds_Hospitals" Width="97%" AllowSorting="True" AutoGenerateColumns="false" 
                                GridLines="None" runat="server" AllowMultiRowSelection="False" BorderStyle="None" OnCancelCommand="DisableGridCommandButtons" 
                                OnSelectedIndexChanged="RadGrid_Hospitals_SelectedIndexChanged" OnEditCommand="DisableGridCommandButtons" OnInsertCommand="DisableGridCommandButtons" 
                                AllowMultiRowEdit="False" HorizontalAlign="NotSet" OnItemDeleted="RadGrid_Hospitals_ItemDeleted"
                                <MasterTableView Width="100%" GridLines="None" CommandItemDisplay="Top" DataSourceID="ds_Hospitals" 
                                    ShowFooter="false" ShowHeader="false" EditMode="InPlace" HorizontalAlign="NotSet" 
                                    DataKeyNames="HospID" AllowAutomaticInserts="True" ClientDataKeyNames="Hospitalname"
                                    <NoRecordsTemplate> 
                                        <div style="width: 200px; margin: 0 auto;"
                                            <br /> 
                                            <br /> 
                                            <b>You currently have no favourites.</b><br /> 
                                            <br /> 
                                            To create a favourite click <b>Add new</b>
                                        </div> 
                                    </NoRecordsTemplate> 
                                    <Columns> 
                                        <telerik:GridBoundColumn DataField="HospID" HeaderText="Hospital" Visible="false"
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="UserID" HeaderText="Hospital" Visible="false"
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="Hospitalname" HeaderText="Hospital"
                                        </telerik:GridBoundColumn> 
                                    </Columns> 
                                    <CommandItemTemplate> 
                                        <telerik:RadToolBar ID="RadToolBar_HospitalCMD" OnButtonClick="RadToolBar_HospitalCMD_ButtonClick" 
                                            runat="server" OnClientButtonClicking="onToolBarClientButtonClicking" Width="100%" AutoPostBack="true"
                                            <Items> 
                                                <telerik:RadToolBarButton Text="Save" CommandName="PerformInsert" ImageUrl="~/images/toolbar/Insert.gif" 
                                                    Visible='<%# RadGrid_Hospitals.MasterTableView.IsItemInserted %>'
                                                </telerik:RadToolBarButton> 
                                                <telerik:RadToolBarButton Text="Update" CommandName="UpdateEdited" ImageUrl="~/images/toolbar/Update.gif" 
                                                    Visible='<%# RadGrid_Hospitals.EditIndexes.Count > 0 %>'
                                                </telerik:RadToolBarButton> 
                                                <telerik:RadToolBarButton Text="Cancel editing" CommandName="CancelAll" ImageUrl="~/images/toolbar/Cancel.gif" 
                                                    Visible='<%# RadGrid_Hospitals.EditIndexes.Count > 0 OrElse RadGrid_Hospitals.MasterTableView.IsItemInserted %>'
                                                </telerik:RadToolBarButton> 
                                                <telerik:RadToolBarButton Text="Edit" CommandName="EditSelected" ImageUrl="~/images/toolbar/Edit.gif" 
                                                    Enabled='<%# RadGrid_Hospitals.EditIndexes.Count = 0 AND Not RadGrid_Hospitals.MasterTableView.IsItemInserted AND hdn_Hosp.value<>"" %>'
                                                </telerik:RadToolBarButton> 
                                                <telerik:RadToolBarButton Text="Add new" CommandName="InitInsert" ImageUrl="~/images/toolbar/AddRecord.gif" 
                                                    Visible='<%# Not RadGrid_Hospitals.MasterTableView.IsItemInserted AND RadGrid_Hospitals.EditIndexes.Count = 0 %>'
                                                </telerik:RadToolBarButton> 
                                                <telerik:RadToolBarButton Text="Delete" CommandName="DeleteSelected" ImageUrl="~/images/toolbar/Delete.gif" 
                                                Enabled='<%# hdn_Hosp.value<>"" %>' Visible='<%# RadGrid_Hospitals.EditIndexes.Count = 0 %>'
                                                </telerik:RadToolBarButton> 
                                            </Items> 
                                        </telerik:RadToolBar> 
                                    </CommandItemTemplate> 
                                </MasterTableView> 
                                <ClientSettings EnablePostBackOnRowClick="true"
                                    <ClientEvents OnRowClick="RowSelected" /> 
                                    <Selecting AllowRowSelect="True" /> 
                                </ClientSettings> 
                            </telerik:RadGrid> 
                        </asp:Panel> 
                    </td> 
                </tr> 
                <tr> 
                    <td align="center"
                     
                        <asp:Button ID="btnSubmit" runat="server" Text="Insert" OnClientClick="returnArg();" UseSubmitBehavior="false" Width="70px" /> 
                    </td> 
                </tr> 
                <tr> 
                    <td align="center"
                        <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClientClick="closeWindow();" UseSubmitBehavior="false" Width="70px" /> 
                    </td> 
                </tr> 
            </table> 
        </asp:Panel> 
    </div> 
    </form> 
 
(there is some other javascript there, but nothing to do with the delete command).

I haven't posted what I've tried as i've tried 15 different ways to replace the delete method with a radconfirm, so thought it would be better to post what I currently have (which works).

If someone can assist with how to implement a radconfirm when using a radtoolbar in a radgrid I would be very grateful.

2 Answers, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 20 May 2010, 01:49 PM
Hello Glen,

I believe that this Code Library will be of help.

Kind regards,
Fiko
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.
0
GlenB
Top achievements
Rank 1
answered on 20 May 2010, 10:32 PM
Thanks Fiko. My solution ended up being here: http://www.telerik.com/community/forums/aspnet-ajax/grid/radconfirm-to-delete-records.aspx

The code library you mentioned will be of great help for the confirmations I wanted to implement on page closures though - thanks.
Tags
Window
Asked by
GlenB
Top achievements
Rank 1
Answers by
Fiko
Telerik team
GlenB
Top achievements
Rank 1
Share this question
or