I have a radButton and in the OnClick method in code behind I am using it to update a bunch of SQL rows.
When a user clicks the button I need to be able to display a pop-up message asking to Confirm Yes/No and if the user clicks No, the OnClick method with the SQL update is no longer fired, only if the user clicks Yes it should fire. Basically if no then stop the postback.
How can this be done?
5 Answers, 1 is accepted

I have tried this http://www.telerik.com/forums/confirmation-message-when-click-rad-button and it does not work, I see the pop up for a second and then it continues with the postback/running the OnClick method without taking any input from the user.
Here is the button code:
<
telerik:RadButton
runat
=
"server"
ID
=
"btnUpdate"
Text
=
"Update Records"
OnClick
=
"btnUpdate_Click"
Skin
=
"Metro"
OnClientClicked
=
"OnClientClicked"
></
telerik:RadButton
>
Here is an example how to achieve your goal:
<telerik:RadButton ID=
"RadButton"
runat=
"server"
OnClientClicking=
"showPrompt"
OnClick=
"RadButton_Click"
Text=
"Prompt button"
></telerik:RadButton>
<script>
function
showPrompt(sender, args) {
var
answer = prompt(
"Do you want to execute a server button click"
,
"Yes"
);
if
(answer.toLocaleLowerCase() ==
"yes"
) {
sender.click();
}
else
args.set_cancel(
true
);
}
</script>
<script runat=
"server"
>
protected void RadButton_Click(object sender, EventArgs e)
{
Response.Write(
"A server click has been executed!"
);
}
</script>
Regards,
Rumen
Progress Telerik

Thanks Rumen, it does work but can I get it to look the same as the standard JS confirm yes/no prompt?
For example it displays a textbox that can be edited by the user which is not ideal.
Hello Silviu,
Yes, you can replace the prompt with confirm method:
<telerik:RadButton ID=
"RadButton"
runat=
"server"
OnClientClicking=
"showPrompt"
OnClick=
"RadButton_Click"
Text=
"Prompt button"
></telerik:RadButton>
<script>
function
showPrompt(sender, args) {
var
answer = confirm(
"Do you want to execute a server button click"
);
if
(answer ==
true
) {
sender.click();
}
else
args.set_cancel(
true
);
}
</script>
<script runat=
"server"
>
protected void RadButton_Click(object sender, EventArgs e)
{
Response.Write(
"A server click has been executed!"
);
}
</script>
Rumen
Progress Telerik
