Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Javascript Confirm using Server Tags

Reply
Thread Tools

Javascript Confirm using Server Tags

 
 
=?Utf-8?B?Q2hyaXMgRmluaw==?=
Guest
Posts: n/a
 
      11-16-2004
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="jsConfirmPopup.aspx.cs"
AutoEventWireup="false" Inherits="playground.jsConfirmPopup" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>jsConfirmPopup</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="JavaScript">
<!--
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="jsConfirmPopup" method="post" runat="server">
<asp:checkbox ID="chkBox1" AutoPostBack="True"
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.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace playground
{
/// <summary>
/// Summary description for jsConfirmPopup.
/// </summary>
public class jsConfirmPopup : System.Web.UI.Page
{
protected System.Web.UI.WebControls.CheckBox chkBox1;

private void Page_Load(object sender, System.EventArgs e)
{
chkBox1.Attributes.Add("onClick","return okCancelConfirm('Are you sure
you want to do this?')");

}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.chkBox1.CheckedChanged += new
System.EventHandler(this.chkBox1_CheckedChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Lables of Confirm Message box using javascript namartajhamb@gmail.com Javascript 1 03-20-2008 05:02 AM
All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer Rob Nicholson ASP .Net 3 05-28-2005 03:11 PM
Run server code on a javascript confirm =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?= ASP .Net 4 12-09-2004 03:57 AM
RegEx to find CFML tags nested in HTML tags Dean H. Saxe Perl 0 01-03-2004 06:11 PM
Using javascript return confirm function within asp.net sub Kathy Burke ASP .Net 2 12-29-2003 04:00 PM



Advertisments