Javascript Confirm box with asp.net

  • Thread starter Thread starter Sudhir
  • Start date Start date
S

Sudhir

I have this piece of code in the HTML view of my asp.net
webform.
-----------------------------------------
<script language="javascript">

var bdirty=false;

function SetDirty(){
bdirty = true;
}

function btncancel_Click(){
if (bdirty)
return confirm("Are you sure you want to skip the
changes?");
}

</script>
----------------------------------------

And in the page behind code I have the following.
-------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load

Textbox1.Attributes.Add("OnChange", "javascript:SetDirty
();")

btncancel.Attributes.Add("onclick", "return btncancel_Click
();")

End Sub
----------------------------------------------------

This works absolutely fine. But when I add a compare
validator to Textbox1 that checks for datatype, the above
code does'nt work. It does'nt give me an error either, but
just ignores it and does'nt call the javascript
btncancel_click function. Just could not understand why it
does that.

Any help is appreciated.

Thanks,
Sudhir.
 
If you don't need to perform any validation while clicking on cancel button
set it's CausesValidation property to false
HTH
 
Back
Top