views:

514

answers:

4

i need to show the confirm box "Are you sure You Want To continue" . if "Yes" i need the asp textbox value to be cleared out. else it should not be cleard.

+1  A: 

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()'/>
anthares
+1  A: 
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

Andrew
A: 

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

Nick Allen - Tungle139
A: 

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>
Naeem Sarfraz