WhatupE
asked on
Getting checkbox "checked" property when disabled by javascript
I have two checkboxes (check1, check2)
When check1 is checked, it remains enabled and enables check2. When check2 is checked, it disables check1. When I go to do my server side validations, I check if check1 is checked. What is occurring is that check1.Checked is always returning false is my server side C# code-behind. Why would this be happening, and more importantly, how can I fix it so that it returns the correct value?
When check1 is checked, it remains enabled and enables check2. When check2 is checked, it disables check1. When I go to do my server side validations, I check if check1 is checked. What is occurring is that check1.Checked is always returning false is my server side C# code-behind. Why would this be happening, and more importantly, how can I fix it so that it returns the correct value?
can u post the code (javascript and codebehind)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls. CheckBox CheckBox1;
protected System.Web.UI.WebControls. Button Button1;
protected System.Web.UI.WebControls. TextBox TextBox1;
protected System.Web.UI.WebControls. Button Button2;
protected System.Web.UI.WebControls. TextBox TextBox2;
protected System.Web.UI.WebControls. CheckBox CheckBox2;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
this.CheckBox2.Attributes. Add("oncli ck", "CheckEmployment('" +
this.CheckBox1.ClientID + "','" +
this.CheckBox2.ClientID +
"');");
}
#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.Button1.Click += new System.EventHandler(this.B utton1_Cli ck);
this.Button2.Click += new System.EventHandler(this.B utton2_Cli ck);
this.Load += new System.EventHandler(this.P age_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
this.TextBox1.Text = this.CheckBox1.Checked.ToS tring();
}
private void Button2_Click(object sender, System.EventArgs e)
{
this.TextBox2.Text = this.CheckBox1.Enabled.ToS tring();
}
}
}
function CheckEmployment(employChk, retireChk)
{
var isChecked = document.getElementById(re tireChk).c hecked;
document.getElementById(em ployChk).d isabled=is Checked;
document.getElementById(em ployChk).c hecked=tru e;
}
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 WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.
protected System.Web.UI.WebControls.
protected System.Web.UI.WebControls.
protected System.Web.UI.WebControls.
protected System.Web.UI.WebControls.
protected System.Web.UI.WebControls.
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
this.CheckBox2.Attributes.
this.CheckBox1.ClientID + "','" +
this.CheckBox2.ClientID +
"');");
}
#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.Button1.Click += new System.EventHandler(this.B
this.Button2.Click += new System.EventHandler(this.B
this.Load += new System.EventHandler(this.P
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
this.TextBox1.Text = this.CheckBox1.Checked.ToS
}
private void Button2_Click(object sender, System.EventArgs e)
{
this.TextBox2.Text = this.CheckBox1.Enabled.ToS
}
}
}
function CheckEmployment(employChk,
{
var isChecked = document.getElementById(re
document.getElementById(em
document.getElementById(em
}
ASKER
raterus -
i tried setting the control value visible = false, but then the javascript blew up when i tried to set the checked value of the invisible control
i tried setting the control value visible = false, but then the javascript blew up when i tried to set the checked value of the invisible control
I'm not talking about the server side visibility, that will make it so it will not even render to the client, not what you want. You must make it invisible in the html source that is sent to the client.
for example:
<input type="checkbox" id="myInvisibleCheckbox" style="visibility: hidden" />
--Michael
for example:
<input type="checkbox" id="myInvisibleCheckbox" style="visibility: hidden" />
--Michael
ASKER
thanks, michael
ASKER