1

I need to show the confirm box "Are you sure You Want To continue?" If "Yes" I need the ASP.NET textbox value to be cleared out. Otherwise it should not be cleared.

2
  • You need to be more specific. Do you need it to be triggered by a submit button or...??? A javascript confirm box or a modal dialog or ??? Commented Feb 8, 2010 at 9:25
  • i need this to be displayed while a radio button is clicked Commented Feb 8, 2010 at 9:30

5 Answers 5

2

In your asp textbox tag add this:

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 on click of your radio box, put it in this tag and just replace onclientclick with onclick.

<input type='radio' onclick='testDeleteValue()'/>
Sign up to request clarification or add additional context in comments.

Comments

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

}

Note the myAspTextBox refers to the name of the asp:textbox controls ID property

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

Hope this helps

Comments

1

If you download the AjaxControlToolkit you can use the ConfirmButtonExtender to display a simple confirmation box to a user after a button is clicked to proceed with the action or cancel

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

Okay I just noticed the bit about radio buttons, in any case the AjaxControlToolkit is a good place to start if you want to implement JavaScript solutions in .Net projects

Comments

0

if this is your textbox markup:

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

and then this is the button that will trigger the confirm:

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

then you'll 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 to clear the textbox but always continue with the postback then you don't ever need to return false as above but always return true as below. In this scenario you should rethink the message you display 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>

Comments

0
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");
}

There is also a timer stop doing in the function. The confirmation box if press "Ok" timer stops and also its redirected to new page "Default2.aspx"

else if chosen cancel then nothing happens.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.