I have a button click event and in that after satisfying some condition , i should confirm dialog, if user clicks ok in that dialog, i want to proceed further in my code.
public void imgValidAdd_Click(object sender, ImageClickEventArgs e)
{
try
{
// Some Code
if(A==b)
{
// Open Confirm dialog
if(ok)
{
// Proceed
}
}
}
catch()
{
}
}
I have tried so many approaches, but nothing worked out
How to call confirm message from code behind in asp.net?
in the above link, i tried and implemented but the thing is ,if you don't postback the page, it doesn't work because appendChild command doesn't clear previous values
How do i work on this. help me on this.
You can do something like this:
On aspx side
1) add a button for confirmed clicked
hidden button
<asp:Button ID="btnConfirmed" runat="server" OnClick="btnConfirmed_Clicked" style="display:none"/>
2) add a javascript function for confirm dialog
//Add a javascript openconfirmdialog() on aspx
function openconfirmdialog() {
if(confirm('Confirm message')) {
//fire hidden button click
$('#<%=btnConfirmed.ClientID%>').click();
} else {
//else message
}
}
On aspx.cs server side
3) fire javascript function from server side using Page.ClientScript
public void imgValidAdd_Click(object sender, ImageClickEventArgs e)
{
try
{
// Some Code
if(A==b)
{
// Open Confirm dialog
Page.ClientScript.RegisterStartupScript(typeof(Page), "openconfirmjs", "<script>openconfirmdialog();</script>");
}
}
catch()
{
}
}
4) Add a confirm button click method
public void btnConfirmed_Clicked(object sender, EventArgs e) {
// Proceed
}
You could use window.confirm
https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm
if (window.confirm("Do you really want to ___?")) {
// do thing
} else {
// don't do thing?
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.