Javascript Confirm box with asp.net

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.
 
A

Anatoly

If you don't need to perform any validation while clicking on cancel button
set it's CausesValidation property to false
HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,167
Latest member
SusanaSwan
Top