473,836 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript Confirm using Server Tags

My goal is to have an ASP.NET checkbox server tag with it's autopostback set
to true, that when clicked will run the checkbox's CheckedChanged event.
However, I would like to try to add a javascript confirm popup to this
checkbox server control to prevent this event from firing if the cancel
button is checked in the js confirm window. In the example below, I am able
to accomplish this using the input type=checkbox but without the autopostback
feature; but, when using the asp:checkbox the cancel button does not prevent
the CheckedChanged event from firing but it does autopostback. I understand
the problem that the onclick attribute is being added in a span tag and the
checkbox's onclick is handling the postback, but not sure how to design
around this and accomplish the desired result....btw, is there a way to turn
off the compiler from autogenerating all the javascript postback code in a
webform?

Below is an example:
====.aspx====== =
<%@ Page language="c#" Codebehind="jsC onfirmPopup.asp x.cs"
AutoEventWireup ="false" Inherits="playg round.jsConfirm Popup" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>jsConfir mPopup</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio 7.0">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
<script language="JavaS cript">
<!--
function okCancelConfirm (msg)
{
var answer = confirm (msg)
if (answer)
{
alert("T");
return true; // submit page
}
else
{
alert("F");
return false; // cancel page submission
}
}
//-->
</script>
</head>
<body MS_POSITIONING= "GridLayout ">
<form id="jsConfirmPo pup" method="post" runat="server">
<asp:checkbox ID="chkBox1" AutoPostBack="T rue"
Runat="server"> </asp:checkbox>
<input type="checkbox" id="chkBox2" onclick="return okCancelConfirm ('Are
you sure you want to do this?')"></input>
</form>
</body>
</html>

===.cs========= ==
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace playground
{
/// <summary>
/// Summary description for jsConfirmPopup.
/// </summary>
public class jsConfirmPopup : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Chec kBox chkBox1;

private void Page_Load(objec t sender, System.EventArg s e)
{
chkBox1.Attribu tes.Add("onClic k","return okCancelConfirm ('Are you sure
you want to do this?')");

}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.chkBox1.Ch eckedChanged += new
System.EventHan dler(this.chkBo x1_CheckedChang ed);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void chkBox1_Checked Changed(object sender, System.EventArg s e)
{
Response.Write( "Checked Changed Event Fired");
}
}
}

Nov 18 '05 #1
0 3724

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

Similar topics

8
4037
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 has a Button. When the Button is clicked, I want a JavaScript confirm dialog to pop-up with the options 'OK' & 'Cancel'. I have done this using the following code: Sub Page_Load(....) btnClick.Attributes.Add("OnClick", "javascript:return...
0
9812
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10828
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10534
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10244
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9364
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6975
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5644
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5814
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3103
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.