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

How to prevent firing server side methods after client side validation fails

11 Answers 689 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Praveen
Top achievements
Rank 1
Praveen asked on 02 Dec 2011, 10:13 AM
Hi,

I am using radfileexplorer (35 version telerik dll) through a custom provider.I have used some client side functions (eg :onCreatenewfolder,onMovedirectory..etc) to perform foldername,length validation folder's existance checking etc..While doing these,
if any validation is failed , i set args.setCancel(true),return false; statements ;even though server side provider methods (eg: CreateDirectory,MoveDirecory ) firing automatically based on the desired actions.How to prevent these event firing?.Please help me by sending exact code.

Regards,
Praveen.

11 Answers, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 05 Dec 2011, 02:54 PM
Hi Praveen,

To prevent firing a server-side functionality you need to cancel the corresponding client-side event (as you have tried). In order to correctly cancel client-side event you need to call set_cancel(true) (not args.setCancel(true)) method in the event handler.

Could you please correct this error and see if the execution is canceled properly?

Regards,
Dobromir
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Robert Fuess
Top achievements
Rank 1
answered on 12 Dec 2011, 09:33 PM
Very interesting.  I am working on similar issues.

Are your examples in http://www.telerik.com/help/aspnet-ajax/fileexplorer-client-side-events.html incorrect?  They show using args.set_cancel(true);

When would we use args.set_cancel(true) and when just set_cancel(true)?
0
Robert Fuess
Top achievements
Rank 1
answered on 13 Dec 2011, 07:44 AM
I just tried using set_cancel(true)
This gets a javascript Undefined error...

The args.set_cancel(true) doesnt get this Undefined error - but doesnt cancel the postback... Any ideas?

I'm trying to do some javascript validation in OnClientCreateNewFolder.  If validation fails (like a folder with that name exists... or invalid characters) , I dont want to create the folder.  I dont want the client script to continue on..
0
Dobromir
Telerik team
answered on 14 Dec 2011, 03:45 PM
Hi Robert,

Please accept my apologies for not being clear enough in my previous post.

The correct way to prevent execution of a client-side event (that is cancelable) is to call set_cancel() method of the arguments object, e.g.:
args.set_cancel(true)

Regarding the issue that you experience, I am not quite sure I understand the exact case. Creating a new folder does not trigger a postback. Do you have custom implementation of this functionality? If so, could you please provide a sample page demonstrating the issue so we can investigate it further?

All the best,
Dobromir
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Shiv
Top achievements
Rank 1
answered on 22 Aug 2016, 09:00 AM

Hello Team,

Its urgent ...we are uisng current version of telerik controls..and i want to firing the server side event when cleint side validation fails.

I have used eventArgs.set_cancel(true);,but it says undefined error.

could you please tell me fast.

 

0
Vessy
Telerik team
answered on 22 Aug 2016, 11:44 AM
Hi Shiv,

I am afraid that the exact scenario you want to achieve is not clear for me. Can you elaborate a bit on:
  • which are the exact server-side events you are trying to prevent and
  • which are the exact client-side events you are to canceling?

Regards,
Vessy
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Gourav
Top achievements
Rank 1
answered on 14 Mar 2019, 05:14 PM

Hi Vessy

I am trying to prevent  event. But args.set_cancel(false); it gives an error "set_cancel" is not a function.

can you tell me fast?

0
Vessy
Telerik team
answered on 15 Mar 2019, 06:39 AM
Hi Gourav,

Can you, please, elaborate a bit on the scenario in which the issue occurs?
  • Which event are you trying to cancel?
  • Can you verify that the args object is defined in the event handler parameters?
  • Can you verify that the event itself is cancelable?

It will be really helpful if you send us a sample setup (including the control declaration and the event handler) so we can see what is causing the issue.

Regards,
Vessy
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Gourav
Top achievements
Rank 1
answered on 15 Mar 2019, 02:14 PM

this is my javascript function

function Validatebutton(sender, eventArgs) {
            
            debugger
            try {
                eventArgs.set_cancel = false;
                var SelectUser = $telerik.findControl(document.documentElement, "drpMarketinguser");
                var Startdate = $telerik.findControl(document.documentElement, "Dpstartdate");
                var ChkMarketing = $telerik.findControl(document.documentElement, "ChkMarketingcredit");
                var dropdown = document.getElementsByClassName("classdrpMarketinguser");
                var datepicker = document.getElementsByClassName("classDpstartdate");
                SelectUser = SelectUser._selectedText;
                ChkMarketing = ChkMarketing._checked;
                Startdate = Startdate._dateInput._displayText;
                if (ChkMarketing) {
                    if (SelectUser == "" && Startdate == "Select Start Date") {
                        dropdown[0].style.backgroundColor = "red";
                        datepicker[0].style.backgroundColor = "red";
                        ChkMarketing._checked = false;
                        //radalert("Please Select User and Enter Start Date",500,200,"Alert");
                        eventArgs.set_cancel=true;
                        
                    }
                    else if (SelectUser == "") {
                        dropdown[0].style.backgroundColor = "red";
                        //radalert("Please Select User", 400, 200, "Alert");
                        ChkMarketing._checked = false;
                        eventArgs.set_cancel=true;
                    }
                    else if (Startdate == "Select Start Date") {
                        datepicker[0].style.backgroundColor = "red";
                       // radalert("Please Enter Start Date", 400, 200, "Alert");
                        ChkMarketing._checked = false;
                        eventArgs.set_cancel=true;
                    }
                   
                }
            }
            catch (err) {
                var msg = err.message;
                eventArgs.set_cancel=true;
            }
           
        }

 

 

 

and this is my button event

 

<telerik:RadButton RenderMode="Lightweight" ID="ApplyButton" runat="server" ButtonType="SkinnedButton" Text="Apply" ToolTip="Apply" BackColor="DodgerBlue" ForeColor="White" OnClick="ApplyButton_Click" CommandName="StayWindow" OnClientClicked="Validatebutton"/>

 

I want to cancel serverside event if client side validation is failed.

0
Vessy
Telerik team
answered on 20 Mar 2019, 11:37 AM
Hi Gourav,

The OnClientClicked event of RadButton is triggered after the click and cannot be canceled:
https://docs.telerik.com/devtools/aspnet-ajax/controls/button/client-side-programming/events/onclientclicked

In order to prevent be able to prevent the click of a button, you have to assign a handler to its OnClientClicking event, which can be canceled:
https://docs.telerik.com/devtools/aspnet-ajax/controls/button/client-side-programming/events/onclientclicking

For example:
<telerik:RadButton RenderMode="Lightweight" ID="ApplyButton" runat="server"
    ButtonType="SkinnedButton" Text="Apply" ToolTip="Apply"
    BackColor="DodgerBlue" ForeColor="White" OnClick="ApplyButton_Click"
    CommandName="StayWindow" OnClientClicking="Validatebutton" />
<script>
    function Validatebutton(sender, eventArgs) {
        eventArgs.set_cancel(true);
    }
</script>


Regards,
Vessy
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Gourav
Top achievements
Rank 1
answered on 20 Mar 2019, 06:11 PM
Hi Vessy, Thanks for , but on .
Tags
FileExplorer
Asked by
Praveen
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Robert Fuess
Top achievements
Rank 1
Shiv
Top achievements
Rank 1
Vessy
Telerik team
Gourav
Top achievements
Rank 1
Share this question
or