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

javascript confirm box and alert on button...

2 Answers 239 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amit
Top achievements
Rank 1
Amit asked on 10 Nov 2010, 10:40 AM
hey everyone,

i have a radgrid.i am using an external button for perfoming delete on selected grid row.i have shown an alert on client side if no row is selected on button click--
function selectedItems()
                    {
                       var MasterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();
                       var selectedItemsCount = MasterTable.get_selectedItems().length;
                       if (selectedItemsCount == 0) {
                       alert("You must select a grid row first before processing DELETE!!");
                       return false;
                       }
                    }
how can i achieve that if no row is selected then the above function runs and if a row is selected then show a confirm box?..
this is my button--
<asp:Button ID="btnDelete" runat="server" Style="margin-right: 25px; color: black;
                   font-weight: bold; margin-left: 25px" Text="Delete" Width="75px" OnClientClick="javascript: return selectedItemsd();"
                   OnClick="btnDelete_Click" CausesValidation="false" />

Thanks
Amit

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 10 Nov 2010, 12:13 PM
Hello Amit,

The following client side code shows how to achieve this.

JavaScript:
<script type="text/javascript">
    function selectedItems() {
        var MasterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();
        var selectedItemsCount = MasterTable.get_selectedItems().length;
        if (selectedItemsCount == 0) {
            alert("You must select a grid row first before processing DELETE!!");
            return false;
        }
        else
            return(!confirm("You have selected" + selectedItemsCount + "  item to DELETE!!"));
    }
</script>


-Shinu.
0
Amit
Top achievements
Rank 1
answered on 10 Nov 2010, 12:42 PM
a little modification-

return(confirm("You have selected" + selectedItemsCount + "  item to DELETE!!")); is working.thanks Shinu
Tags
Grid
Asked by
Amit
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Amit
Top achievements
Rank 1
Share this question
or