I have these lines of code which select checkbox based on preselected flag
if (objX.PreSelected)
{
string js = "if(document.getElementById('" + CheckBoxId + "').checked==false) document.getElementById('" + CheckBoxId + "').click();";
if (!Page.ClientScript.IsStartupScriptRegistered(CheckBoxId))
Page.ClientScript.RegisterStartupScript(this.GetType(), CheckBoxId, js, true);
}
after this is done I need to disable that preselected checkbox. I tried below but it did not work
string js = "if(document.getElementById('" + CheckBoxId + "').checked==false) {document.getElementById('" + CheckBoxId + "').click();document.getElementById('" + CheckBoxId + "').disabled ='disabled';}";
UPDATE - I could disable that checkbox but problem is it's not sent back to server. I am new to asp.net programming, please suggest.Any help would be appreciated.
Do you need to do this with javascript? Otherwise you could do something like:
or
To make a CheckBox disabled using JavaScript you can write
or
No need to do both .click() and .checked = true;