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
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

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)?

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..
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

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.
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

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?
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

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.
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
