473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Javascript Confirm box with asp.net

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.

Nov 17 '05 #1
1 5495
If you don't need to perform any validation while clicking on cancel button
set it's CausesValidation property to false
HTH

"Sudhir" <sk*****@Comsult.com> wrote in message
news:0d****************************@phx.gbl...
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.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Muhammad Abdullah | last post by:
Hi am having some problems with the javascript confirm. i have it working fine on one page and it doesnt even pop up at the other. The code on the working page is, private void...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
7
by: TJS | last post by:
javascript "confirm" fires after deletion instead of before deletion. how do I get this to stop the processing ? code ================== Sub ShowAlert(ByVal s As string)...
12
by: tshad | last post by:
I have the following code that attaches a Javascript confirm box to my checkbox. When I select the checkbox, the window comes up fine, but it never executes the XfertoDefault_Click function when I...
3
by: TJ | last post by:
Hi, I would like to ask something to user after user submits the form... I know I can ask user whehter they want to submit the form or not using client-script code such as onClick or onSubmit by...
8
by: Dave | last post by:
Hello all, I have been able to use a Javascript alert box in my vb.net web application, for example: Dim msg As String = "Hello, world." Dim alertScript As String = "<script...
4
by: tfsmag | last post by:
Okay, I have a project management app i'm writing and in the left hand menu i have a treeview control that is populated with each project... in child nodes under each project node I have an "edit"...
6
by: den 2005 | last post by:
Hi everybody, Question 1: How do you set the values from server-side to a client-side control or how do you execute a javascript function without a button click event? Question 2: How do you...
8
by: rn5a | last post by:
I have gone through a no. of posts in this NewsGroup regarding my problem but alas, couldn't come across one which would have helped me in resolving the issue. My problem is this: An ASPX Form...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.