Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cheecked change event not loading

Status
Not open for further replies.

ystm

Programmer
Nov 28, 2006
4
GB
Whne adding a confirmation box to the checkbox (when its value changed from checked to unchecked), the checked change event will not load.

Any suggestions?

Code:
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<script runat="server">

    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (CheckBox1.Checked == false)
        {
            Response.Write("Checkbox changed value");
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        CheckBox1.Attributes.Add("onclick", "if (!this.checked) {return confirm('Please confirm'); }");
    }
</script>

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack=true />
    </div>
    </form>
</body>
</html>
 
The function has a logic error in it. If you were compiling this in C#, the error would be "Not all code paths return a value.".

Try this:
Code:
....
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckBox1.Attributes.Add("onclick", "OnCheckedChanged(this);");
    }
</script>
<script language="javascript">
  function OnCheckedChanged(p_Obj)
  {
	var output = false;
	if(!p_Obj.checked)
	{
		output = confirm('Please confirm');
	}//if
	return output;
  }//OnCheckedChanged
</script>
....

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top