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

Server Side validation fires after client side validation on RadButton call back function

1 Answer 143 Views
Button
This is a migrated thread and some comments may be shown as answers.
Ankit
Top achievements
Rank 1
Ankit asked on 05 Oct 2011, 11:09 AM

I am having a RadButton control placed outside the grid ,to delete the multiple selected rows from the grid ,
i have written Client side and Server Side Validation Functions to show Pop-Up if User clicks on Delete Button
without selecting any row from the grid saying "Please select item(s) to delete.!!" using Alert().

on doing so ,my Javascript Function gets executed and gives me the desired Alert PopUp ,on clicking ok button of the PopUp it does PostBack which causes Server Side Validation to fire,
Due to which i am getting 2 PopUps one from Client Side and another From Server Side Code one after the other.

Javascript Function is given below :-

function DeleteSelectedItems(sender, args) {
        var Count=0;
        var grid = $find("<%=grdSearchResults.ClientID %>");
        var masterTable = grid.get_masterTableView();
        for (var i = 0; i < masterTable.get_dataItems().length; i++) {
            var gridStatementElement = masterTable.get_dataItems()[i].findElement("chkSelect");
              
            if (gridStatementElement != null && gridStatementElement.checked==true) {
                Count = Count + 1;
            }
        }
        if (Count == 0) {     //This part is not working fine 
            alert("Please select item(s) to delete.!!") ;
            return false;
             
        }
        else if(Count>0){      //This is working Fine
            ConfirmDeletion(sender, args);
  
        }

Call to Javascript method from RadButton :-

<telerik:RadButton ID="btnDelete" runat="server" Visible="false"
                            Text="Delete"  OnClick="btnDelete_Click" OnClientClicking ="DeleteSelectedItems" >
                            <Icon PrimaryIconUrl="../Images/Common/Delete-icon.png" />
</telerik:RadButton>

I want to stop this additional PostBack so that my Server side validation will not fire.

1 Answer, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 05 Oct 2011, 01:28 PM
Hello Ankit,

In your code replace the line "return false" with "args.set_cancel(true)", which will prevent the button from causing a postback.

I hope that helps.
Tags
Button
Asked by
Ankit
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Share this question
or