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

Confirm Yes/No on button click

5 Answers 991 Views
Button
This is a migrated thread and some comments may be shown as answers.
Silviu
Top achievements
Rank 1
Silviu asked on 02 Aug 2017, 12:18 PM

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

Sort by
0
Silviu
Top achievements
Rank 1
answered on 02 Aug 2017, 01:01 PM

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>
0
Rumen
Telerik team
answered on 04 Aug 2017, 03:12 PM
Hi,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Silviu
Top achievements
Rank 1
answered on 08 Aug 2017, 11:08 AM

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.

0
Rumen
Telerik team
answered on 08 Aug 2017, 12:08 PM

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>

Regards,
Rumen
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Silviu
Top achievements
Rank 1
answered on 08 Aug 2017, 01:16 PM
Thanks Rumen, that's exactly what I needed.
Tags
Button
Asked by
Silviu
Top achievements
Rank 1
Answers by
Silviu
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or