Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a submit button on modalpopupextender.
I have to open a confirmation box on a specific condition inside the submit button.
I am able to open the confirmation box.But when user clicks on the ok button
of the confirmation box i want to execute some code.
How can i handlethe event of Ok button of the confirmation box?

Here is my code:
C#
protected void BtnSubmitSurveyInfo_Click(object sender, EventArgs e)
{
      if()
     {
          //some code.
     }
     else
     {
          BtnSubmitSurveyInfo.Attributes.Add("onclick", "if(confirm('Confirm - Are you sure you want to go ahead.')) onConfirm(); else return false;");
     }
}
Posted
Updated 6-Sep-13 1:37am
v2
Comments
ZurdoDev 6-Sep-13 7:34am    
Where is your code? Are you using confirm() in JS? If so, it's a function. It returns true or false.
Thomas ktg 6-Sep-13 8:00am    
Do you want to execute code in the server side after clicking on the ok button in the Confirmation box?
Thomas ktg 6-Sep-13 8:21am    
Add the button Submit Attributes inside
Page_Load(object sender, EventArgs e){
btnAddItem.Attributes.Add("onclick", "{return validateinput()};");
}
like this
Priyanka7777 6-Sep-13 8:02am    
Yes.I want to save the information entered once the user clicks on OK button.
ZurdoDev 6-Sep-13 8:08am    
You could just try using the OnClientClick property of the button. But it looks like your code is not running. Are you sure it is adding the onclick event to your button? Put a breakpoint on your if In C# and make sure the attribute is actually added because the JS looks ok.

which code you want to execute and your syntax is wrong
C#
BtnSubmitSurveyInfo.Attributes.Add("onclick", " var aa=confirm('Confirm - Are you sure you want to go ahead.')if (aa==true){your code}else {your code}");



this would we also handy

[update]

JavaScript
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "script", "<script type='text/javascript'>var x = window.confirm('Do you want to assign pages to this advertise?');if(x){code}</script>", false);



regards....:)
 
Share this answer
 
v4
Comments
Priyanka7777 6-Sep-13 7:50am    
Sorry i added your code,but it is not working.Confirmation box is not opening.
Dholakiya Ankit 6-Sep-13 7:57am    
what error you are getting check in your console
Priyanka7777 6-Sep-13 8:03am    
I am not getting any error.Nut the confirmation box is not shown.
Mahesh Bailwal 6-Sep-13 8:08am    
can you share view source of this page?
Dholakiya Ankit 6-Sep-13 8:13am    
share source of your code
Hi,

Try like this:
HTML
<html>
<head>
<pre lang="Javascript"><script>
function myFunction()
{
if(confirm("Do You want to Execurte Below Code?")){
//code to execute when click on Yes
}else{
//else
}
}
</script>

</head>
<body>

<asp: Button ID="btnTest" OnClientClick="return myFunction();" Text="Show Confirm" runat="server" />

</body>
</html>
 
Share this answer
 
v2

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