Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a asp button control, on click of this button one pop-up should appear which should ask YES or NO option, on selection of yes option from this pop-up should call a function from aspx.cs page.


ASPX PAGE:
<asp:Button ID="Button1" runat="server"  OnClick="Button1_Click"  Text ="Button" />


ASPX.CS PAGE:

protected void Button1_Click(object sender, EventArgs e)
        {
            DoSomethingMethod(){ }
        }





on click of button1 popup need to be triggered, triggered popup should have 2 options like YES or NO,
on selection of YES i should call DoSomethingMethod() , and on selection of NO do nothing.

What I have tried:

i'm not getting any idea on this, solution can be ok with jquery, javascript,asp validation anything is fine.
Posted
Updated 23-Aug-19 7:31am

1 solution

You'll have to do this in Javascript, since your C# code is running on the server and cannot interact with the user.
ASP.NET
<asp:Button ID="Button1" runat="server"
    OnClientClick="if(!confirm('Really do the thing?')){return false;}"
    OnClick="Button1_Click"
    Text="Button"
/>
Button.OnClientClick Property (System.Web.UI.WebControls) | Microsoft Docs[^]
Window.confirm() - Web APIs | MDN[^]
 
Share this answer
 
Comments
Virendra S from Bangalore, Karnataka 23-Aug-19 14:45pm    
Window.confirm() is helpful but i am looking for some standard popup box just like jquery dialog box, can you help me in this?
Richard Deeming 27-Aug-19 7:18am    
There is no standard popup box, other than alert and confirm.

If you use something like jQuery's dialog box, or Bootstrap's modal, then it gets more complicated. Displaying the dialog won't stop the form from being submitted, so you'll need more code to manage the submission process. For example:
var clickedButton = null;

function displayConfirmation(evt){
    if (clickedButton === evt.target) {
        return;
    }
    
    evt.preventDefault();
    clickedButton = evt.target;
    // Display your dialog box here...
}

function dialogOkButtonClicked(){
    // Hide the dialog box here...
    clickedButton.click();
}

function dialogCancelButtonClicked(){
    // Hide the dialog box here...
    clickedButton = null;
}


Alternatively, you may be able to use the showModalDialog polyfill[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900