Display confirmation window in ASP.NET using JavaScript

I need to show a confirmation window "Are you sure you want to continue?" If yes, I need the ASP.NET text box to be cleared. Otherwise, it should not be cleaned.

+1
source share
5 answers
function doConfirm(){ if (confirm("Are you sure you want to continue?")){ var mytxtbox = document.getElementById('<% =myAspTextBox.ClientID %>'); mytxtbox.value = ''; } } 

Notice that myAspTextBox refers to the property name of the asp object ID: textbox

 <asp:textbox ID="myAspTextBox" runat="server" OnClientClick="javascript:doConfirm();" 

Hope this helps

+1
source

In the asp text tag tag, add the following:

 OnClientClick="javascript:testDeleteValue();" 

... And add this script:

 <script> function testDeleteValue() { if (window.confirm('Are you sure You Want To continue?')) document.getElementById("<%=<th id of your textbox>.ClientID%>").value = ''; } </script> 

If you want this to happen when you click your radio box, put it in this tag and just replace onclientclick with onclick.

 <input type='radio' onclick='testDeleteValue()'/> 
+1
source

If you download AjaxControlToolkit , you can use ConfirmButtonExtender to display a simple confirmation window to the user after clicking on the button to perform an action or cancel

You can see here for an example and here for a tutorial on how to implement this

Ok, I just noticed a little about the switches, anyway AjaxControlToolkit is a good place to start if you want to implement JavaScript solutions in .Net projects

+1
source

if this is your textbox markup:

 <asp:textbox id="txtInput" runat="server" /> 

and then this is the button that activates the confirmation:

 <asp:button id="btnSumbit" runat="server" onclientclick="return clearOnConfirm();" text="Submit" /> 

then you will need the following javascript:

 <script type="text/javascript"> function clearOnConfirm() { if (confirm("Are you sure you want to continue?")) { document.getElementById("<%=txtInput.ClientID %>").value = ''; return true; } else { return false; } } </script> 

If all you want to do is clear the text box, but always continue to transmit, then you do not need to return false as above, but always return true, as shown below. In this case, you must rethink the message displayed to the user.

 <script type="text/javascript"> function clearOnConfirm() { if (confirm("Are you sure you want to continue?")) { document.getElementById("<%=txtInput.ClientID %>").value = ''; } return true; } </script> 
0
source
 function stopTimer() { if (window.confirm('Are you sure You Want To continue?')) { $find('Timer1')._stopTimer() return true; } else { return false; } <asp:Button ID="Btn_Finish" runat="server" Text="Finish" Width="113px" OnClick="Btn_Finish_Click" OnClientClick="return stopTimer();" Height="35px" protected void Btn_Finish_Click(object sender, EventArgs e) { Timer1.Enabled = false; // if any functions to be done eg: function1(); Response.Redirect("~/Default2.aspx"); } 

The function also has a timer stop. The confirmation field, if you click "Ok", will stop, and also redirected to the new page "Default2.aspx"

else, if the selected one is canceled, then nothing happens.

0
source

All Articles