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

2 posts, 0 answers
  1. Ankit
    Ankit avatar
    12 posts
    Member since:
    Jul 2011

    Posted 05 Oct 2011 Link to this post

    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.
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 05 Oct 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top