checkbox checked change will disabled the other checkbox
I have two checkboxes. If the first checkbox checked, the second checbox will be disabled and if the first checkbox unchecked, the second checkbox will be enabled.
<div class="data">
<asp:CheckBox ID="firstCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" />
</div>
<div class="data">
<asp:CheckBox ID="secondCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" />
</div>
Here is my control part at the Page_Load;
if (firstCheckBox.Checked)
{
secondCheckBox.Enabled = false;
}
else
{
secondCheckBox.Enabled = true;
}
When I checked the firstcheckbox, nothing happens to the secondcheckbox. After I checked the second checkbox, secondcheckbox has been checked and disabled.
What am I missing?
c# .net checkbox webforms isenabled
add a comment |
I have two checkboxes. If the first checkbox checked, the second checbox will be disabled and if the first checkbox unchecked, the second checkbox will be enabled.
<div class="data">
<asp:CheckBox ID="firstCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" />
</div>
<div class="data">
<asp:CheckBox ID="secondCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" />
</div>
Here is my control part at the Page_Load;
if (firstCheckBox.Checked)
{
secondCheckBox.Enabled = false;
}
else
{
secondCheckBox.Enabled = true;
}
When I checked the firstcheckbox, nothing happens to the secondcheckbox. After I checked the second checkbox, secondcheckbox has been checked and disabled.
What am I missing?
c# .net checkbox webforms isenabled
is this webforms?
– JohnB
Nov 21 '18 at 6:49
yes it is @JohnB
– GAD
Nov 21 '18 at 6:50
did you tried to use FirstCheckBoxCheckedChangedevent ? just putsecondCheckBox.Enabled= ! firstCheckBox.Checked;
– MKH
Nov 21 '18 at 7:06
add a comment |
I have two checkboxes. If the first checkbox checked, the second checbox will be disabled and if the first checkbox unchecked, the second checkbox will be enabled.
<div class="data">
<asp:CheckBox ID="firstCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" />
</div>
<div class="data">
<asp:CheckBox ID="secondCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" />
</div>
Here is my control part at the Page_Load;
if (firstCheckBox.Checked)
{
secondCheckBox.Enabled = false;
}
else
{
secondCheckBox.Enabled = true;
}
When I checked the firstcheckbox, nothing happens to the secondcheckbox. After I checked the second checkbox, secondcheckbox has been checked and disabled.
What am I missing?
c# .net checkbox webforms isenabled
I have two checkboxes. If the first checkbox checked, the second checbox will be disabled and if the first checkbox unchecked, the second checkbox will be enabled.
<div class="data">
<asp:CheckBox ID="firstCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" />
</div>
<div class="data">
<asp:CheckBox ID="secondCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" />
</div>
Here is my control part at the Page_Load;
if (firstCheckBox.Checked)
{
secondCheckBox.Enabled = false;
}
else
{
secondCheckBox.Enabled = true;
}
When I checked the firstcheckbox, nothing happens to the secondcheckbox. After I checked the second checkbox, secondcheckbox has been checked and disabled.
What am I missing?
c# .net checkbox webforms isenabled
c# .net checkbox webforms isenabled
edited Nov 21 '18 at 8:15
Reza Aghaei
68.4k858172
68.4k858172
asked Nov 21 '18 at 6:47
GADGAD
154
154
is this webforms?
– JohnB
Nov 21 '18 at 6:49
yes it is @JohnB
– GAD
Nov 21 '18 at 6:50
did you tried to use FirstCheckBoxCheckedChangedevent ? just putsecondCheckBox.Enabled= ! firstCheckBox.Checked;
– MKH
Nov 21 '18 at 7:06
add a comment |
is this webforms?
– JohnB
Nov 21 '18 at 6:49
yes it is @JohnB
– GAD
Nov 21 '18 at 6:50
did you tried to use FirstCheckBoxCheckedChangedevent ? just putsecondCheckBox.Enabled= ! firstCheckBox.Checked;
– MKH
Nov 21 '18 at 7:06
is this webforms?
– JohnB
Nov 21 '18 at 6:49
is this webforms?
– JohnB
Nov 21 '18 at 6:49
yes it is @JohnB
– GAD
Nov 21 '18 at 6:50
yes it is @JohnB
– GAD
Nov 21 '18 at 6:50
did you tried to use FirstCheckBox
CheckedChanged event ? just put secondCheckBox.Enabled= ! firstCheckBox.Checked;– MKH
Nov 21 '18 at 7:06
did you tried to use FirstCheckBox
CheckedChanged event ? just put secondCheckBox.Enabled= ! firstCheckBox.Checked;– MKH
Nov 21 '18 at 7:06
add a comment |
3 Answers
3
active
oldest
votes
You can use javascript to enable or disable checkbox.
Here firstCheckBox & secondCheckBox are the id's of your checkbox.
if(document.getElementById("firstCheckBox").checked = true)
document.getElementById("secondCheckBox").disabled = true;
else
document.getElementById("secondCheckBox").disabled = false;
For standard setup you should usedocument.getElementById("<%= firstCheckBox.ClientID %>"). Server controls may rendered with differentidvalue unlessClientIDMode="Static"is used.
– Tetsuya Yamamoto
Nov 21 '18 at 7:21
add a comment |
You can do it with checkBox CheckChanged event.
Please remove condition from load event of your form and add below code.
<div class="data">
<asp:CheckBox ID="firstCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" OnCheckedChanged="CheckBox1_Check_Clicked" />
</div>
<div class="data">
<asp:CheckBox ID="secondCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" OnCheckedChanged="CheckBox2_Check_Clicked" />
</div>
protected void CheckBox1_Check_Clicked(Object sender, EventArgs e)
{
if(CheckBox1.Checked==true)
{
CheckBox2.Enable=false;
}
else
{
CheckBox2.Enable=true;
}
}
protected void CheckBox2_Check_Clicked(Object sender, EventArgs e)
{
if(CheckBox2.Checked==true)
{
CheckBox1.Enable=false;
}
else
{
CheckBox1.Enable=true;
}
}
So you should have two CheckChanged events on each checkbox individual. Autopostback true. Same you can do with only one event if you apply some logic.
add a comment |
I assumed that you want to set Enabled state of second checkbox in server-side, hence you should handle CheckedChanged event from first checkbox like this example:
private void firstCheckBox_CheckedChanged(object sender, EventArgs e)
{
secondCheckBox.Enabled = !firstCheckBox.Checked;
}
The problem why the checkbox checked event handler is not triggered is because you're putting the logic inside Page_Load event instead of CheckedChanged event from first checkbox.
Similar issue:
If one checkbox is checked, set the other to unchecked
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406614%2fcheckbox-checked-change-will-disabled-the-other-checkbox%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use javascript to enable or disable checkbox.
Here firstCheckBox & secondCheckBox are the id's of your checkbox.
if(document.getElementById("firstCheckBox").checked = true)
document.getElementById("secondCheckBox").disabled = true;
else
document.getElementById("secondCheckBox").disabled = false;
For standard setup you should usedocument.getElementById("<%= firstCheckBox.ClientID %>"). Server controls may rendered with differentidvalue unlessClientIDMode="Static"is used.
– Tetsuya Yamamoto
Nov 21 '18 at 7:21
add a comment |
You can use javascript to enable or disable checkbox.
Here firstCheckBox & secondCheckBox are the id's of your checkbox.
if(document.getElementById("firstCheckBox").checked = true)
document.getElementById("secondCheckBox").disabled = true;
else
document.getElementById("secondCheckBox").disabled = false;
For standard setup you should usedocument.getElementById("<%= firstCheckBox.ClientID %>"). Server controls may rendered with differentidvalue unlessClientIDMode="Static"is used.
– Tetsuya Yamamoto
Nov 21 '18 at 7:21
add a comment |
You can use javascript to enable or disable checkbox.
Here firstCheckBox & secondCheckBox are the id's of your checkbox.
if(document.getElementById("firstCheckBox").checked = true)
document.getElementById("secondCheckBox").disabled = true;
else
document.getElementById("secondCheckBox").disabled = false;
You can use javascript to enable or disable checkbox.
Here firstCheckBox & secondCheckBox are the id's of your checkbox.
if(document.getElementById("firstCheckBox").checked = true)
document.getElementById("secondCheckBox").disabled = true;
else
document.getElementById("secondCheckBox").disabled = false;
answered Nov 21 '18 at 7:06
Bhargav AbotiBhargav Aboti
23310
23310
For standard setup you should usedocument.getElementById("<%= firstCheckBox.ClientID %>"). Server controls may rendered with differentidvalue unlessClientIDMode="Static"is used.
– Tetsuya Yamamoto
Nov 21 '18 at 7:21
add a comment |
For standard setup you should usedocument.getElementById("<%= firstCheckBox.ClientID %>"). Server controls may rendered with differentidvalue unlessClientIDMode="Static"is used.
– Tetsuya Yamamoto
Nov 21 '18 at 7:21
For standard setup you should use
document.getElementById("<%= firstCheckBox.ClientID %>"). Server controls may rendered with different id value unless ClientIDMode="Static" is used.– Tetsuya Yamamoto
Nov 21 '18 at 7:21
For standard setup you should use
document.getElementById("<%= firstCheckBox.ClientID %>"). Server controls may rendered with different id value unless ClientIDMode="Static" is used.– Tetsuya Yamamoto
Nov 21 '18 at 7:21
add a comment |
You can do it with checkBox CheckChanged event.
Please remove condition from load event of your form and add below code.
<div class="data">
<asp:CheckBox ID="firstCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" OnCheckedChanged="CheckBox1_Check_Clicked" />
</div>
<div class="data">
<asp:CheckBox ID="secondCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" OnCheckedChanged="CheckBox2_Check_Clicked" />
</div>
protected void CheckBox1_Check_Clicked(Object sender, EventArgs e)
{
if(CheckBox1.Checked==true)
{
CheckBox2.Enable=false;
}
else
{
CheckBox2.Enable=true;
}
}
protected void CheckBox2_Check_Clicked(Object sender, EventArgs e)
{
if(CheckBox2.Checked==true)
{
CheckBox1.Enable=false;
}
else
{
CheckBox1.Enable=true;
}
}
So you should have two CheckChanged events on each checkbox individual. Autopostback true. Same you can do with only one event if you apply some logic.
add a comment |
You can do it with checkBox CheckChanged event.
Please remove condition from load event of your form and add below code.
<div class="data">
<asp:CheckBox ID="firstCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" OnCheckedChanged="CheckBox1_Check_Clicked" />
</div>
<div class="data">
<asp:CheckBox ID="secondCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" OnCheckedChanged="CheckBox2_Check_Clicked" />
</div>
protected void CheckBox1_Check_Clicked(Object sender, EventArgs e)
{
if(CheckBox1.Checked==true)
{
CheckBox2.Enable=false;
}
else
{
CheckBox2.Enable=true;
}
}
protected void CheckBox2_Check_Clicked(Object sender, EventArgs e)
{
if(CheckBox2.Checked==true)
{
CheckBox1.Enable=false;
}
else
{
CheckBox1.Enable=true;
}
}
So you should have two CheckChanged events on each checkbox individual. Autopostback true. Same you can do with only one event if you apply some logic.
add a comment |
You can do it with checkBox CheckChanged event.
Please remove condition from load event of your form and add below code.
<div class="data">
<asp:CheckBox ID="firstCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" OnCheckedChanged="CheckBox1_Check_Clicked" />
</div>
<div class="data">
<asp:CheckBox ID="secondCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" OnCheckedChanged="CheckBox2_Check_Clicked" />
</div>
protected void CheckBox1_Check_Clicked(Object sender, EventArgs e)
{
if(CheckBox1.Checked==true)
{
CheckBox2.Enable=false;
}
else
{
CheckBox2.Enable=true;
}
}
protected void CheckBox2_Check_Clicked(Object sender, EventArgs e)
{
if(CheckBox2.Checked==true)
{
CheckBox1.Enable=false;
}
else
{
CheckBox1.Enable=true;
}
}
So you should have two CheckChanged events on each checkbox individual. Autopostback true. Same you can do with only one event if you apply some logic.
You can do it with checkBox CheckChanged event.
Please remove condition from load event of your form and add below code.
<div class="data">
<asp:CheckBox ID="firstCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" OnCheckedChanged="CheckBox1_Check_Clicked" />
</div>
<div class="data">
<asp:CheckBox ID="secondCheckBox" runat="server" CssClass="LabelText" EnableViewState="False" AutoPostBack="True" OnCheckedChanged="CheckBox2_Check_Clicked" />
</div>
protected void CheckBox1_Check_Clicked(Object sender, EventArgs e)
{
if(CheckBox1.Checked==true)
{
CheckBox2.Enable=false;
}
else
{
CheckBox2.Enable=true;
}
}
protected void CheckBox2_Check_Clicked(Object sender, EventArgs e)
{
if(CheckBox2.Checked==true)
{
CheckBox1.Enable=false;
}
else
{
CheckBox1.Enable=true;
}
}
So you should have two CheckChanged events on each checkbox individual. Autopostback true. Same you can do with only one event if you apply some logic.
answered Nov 21 '18 at 7:06
NakulNakul
1069
1069
add a comment |
add a comment |
I assumed that you want to set Enabled state of second checkbox in server-side, hence you should handle CheckedChanged event from first checkbox like this example:
private void firstCheckBox_CheckedChanged(object sender, EventArgs e)
{
secondCheckBox.Enabled = !firstCheckBox.Checked;
}
The problem why the checkbox checked event handler is not triggered is because you're putting the logic inside Page_Load event instead of CheckedChanged event from first checkbox.
Similar issue:
If one checkbox is checked, set the other to unchecked
add a comment |
I assumed that you want to set Enabled state of second checkbox in server-side, hence you should handle CheckedChanged event from first checkbox like this example:
private void firstCheckBox_CheckedChanged(object sender, EventArgs e)
{
secondCheckBox.Enabled = !firstCheckBox.Checked;
}
The problem why the checkbox checked event handler is not triggered is because you're putting the logic inside Page_Load event instead of CheckedChanged event from first checkbox.
Similar issue:
If one checkbox is checked, set the other to unchecked
add a comment |
I assumed that you want to set Enabled state of second checkbox in server-side, hence you should handle CheckedChanged event from first checkbox like this example:
private void firstCheckBox_CheckedChanged(object sender, EventArgs e)
{
secondCheckBox.Enabled = !firstCheckBox.Checked;
}
The problem why the checkbox checked event handler is not triggered is because you're putting the logic inside Page_Load event instead of CheckedChanged event from first checkbox.
Similar issue:
If one checkbox is checked, set the other to unchecked
I assumed that you want to set Enabled state of second checkbox in server-side, hence you should handle CheckedChanged event from first checkbox like this example:
private void firstCheckBox_CheckedChanged(object sender, EventArgs e)
{
secondCheckBox.Enabled = !firstCheckBox.Checked;
}
The problem why the checkbox checked event handler is not triggered is because you're putting the logic inside Page_Load event instead of CheckedChanged event from first checkbox.
Similar issue:
If one checkbox is checked, set the other to unchecked
answered Nov 21 '18 at 7:06
Tetsuya YamamotoTetsuya Yamamoto
16.8k42242
16.8k42242
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406614%2fcheckbox-checked-change-will-disabled-the-other-checkbox%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
is this webforms?
– JohnB
Nov 21 '18 at 6:49
yes it is @JohnB
– GAD
Nov 21 '18 at 6:50
did you tried to use FirstCheckBox
CheckedChangedevent ? just putsecondCheckBox.Enabled= ! firstCheckBox.Checked;– MKH
Nov 21 '18 at 7:06