David Wilson
Top achievements
Rank 2
David Wilson
asked on 18 Apr 2008, 04:36 PM
What is the proper technique to cancel a button clicked on the RadToolBar.
Simplistically, I'd like to do something like the following in code behind:
But this JavaScript does not cancel the call back to the server.
Any ideas?
Thanks.
--David
Simplistically, I'd like to do something like the following in code behind:
Me.RadToolBar1.Items(1).Attributes.Add("onclick", "if(!confirm('Are you sure you want to delete this item?')) return false;") |
But this JavaScript does not cancel the call back to the server.
Any ideas?
Thanks.
--David
5 Answers, 1 is accepted
0
Accepted
Hello David Wilson,
I suggest that you subscribe to the OnClientButtonClicking event and cancel it if the user does not confirm.
I hope this helps.
Kind regards,
Veskoni
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I suggest that you subscribe to the OnClientButtonClicking event and cancel it if the user does not confirm.
I hope this helps.
Kind regards,
Veskoni
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
terrysmith
Top achievements
Rank 1
answered on 23 Apr 2008, 04:21 PM
I am having the same problem. On a button click I want to fire some Javascript code and prevent a server postback.
If I do this:
function OnClientButtonClicking(sender, args)
{
args.set_cancel(true);
var button = args.get_item();
if (button.get_value() == "print")
{
window.print();
}
I get this error:
Microsoft JScript runtime error: Object doesn't support this property or method
on the args.set_cancel line. If I try canceling it this way it doesn't throw any errors but the server-side ButtonClick event is still hit:
function OnClientButtonClicking(sender, args)
{
var domEvent = args.get_domEvent();
// Stop IE from showing its context menu.
domEvent.cancelBubble = true;
if (domEvent.stopPropagation)
{
domEvent.stopPropagation();
}
domEvent.returnValue = false;
var button = args.get_item();
if (button.get_value() == "print")
{
window.print();
}
If I do this:
function OnClientButtonClicking(sender, args)
{
args.set_cancel(true);
var button = args.get_item();
if (button.get_value() == "print")
{
window.print();
}
I get this error:
Microsoft JScript runtime error: Object doesn't support this property or method
on the args.set_cancel line. If I try canceling it this way it doesn't throw any errors but the server-side ButtonClick event is still hit:
function OnClientButtonClicking(sender, args)
{
var domEvent = args.get_domEvent();
// Stop IE from showing its context menu.
domEvent.cancelBubble = true;
if (domEvent.stopPropagation)
{
domEvent.stopPropagation();
}
domEvent.returnValue = false;
var button = args.get_item();
if (button.get_value() == "print")
{
window.print();
}
0
Hi guys,
Please, find attached a small page, demonstrating the button click cancellation. Terry, could it be that you've actually subscribed to the OnClientButtonClicked event?
Cheers,
Erjan Gavalji
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Please, find attached a small page, demonstrating the button click cancellation. Terry, could it be that you've actually subscribed to the OnClientButtonClicked event?
Cheers,
Erjan Gavalji
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
terrysmith
Top achievements
Rank 1
answered on 23 Apr 2008, 06:47 PM
You're right. I would have swore that I changed OnClientButtonClicked to OnClientButtonClicking, but after the leaving the code for awhile and then coming back to it I quickly saw that I had not changed it.
Thanks!
Terry
0
Roberto
Top achievements
Rank 1
answered on 07 May 2008, 07:46 PM
Hello,
I resolve with a java confirm invoked in OnClientItemClicking
I resolve with a java confirm invoked in OnClientItemClicking
<
script type="text/javascript">
function onMyClicked(sender, args)
{
var btn = args.get_item().get_value();
if (btn == 'IDDelete') {
var result = confirm("Are you sure you clicked: " + btn);
if (! result){
args.set_cancel(
true);
}
}
}
</
script>
Kind regards