I have a toggle button that works fine, applied to a CheckBox (ToggleButtonExtender). When I click it, the images change and everything works fine. I have a situation where I need to set the Checked property to true in code. When I do this, the ToggleButton
doesn't reflect this change visually even though the CheckBox is "checked". How do you force this change visually to make it programmatically change its images in accordance with the state of the CheckBox?
Its as if the ToggleButton(Extender) doesn't respond to programmatic changes, only click events. How do you circumvent this?
If my CheckBox (with the ToggleButtonExtender) is called chkSendInvitation_1_4
and the ToggleButtonExtender is called tbxSendInvitationExtender
how does it relate to the above code? Also, I'm using C# (sorry for not clarifying this) although any example I can probably convert once I know how the above names in my code relate to the RegisterStartupScript code you posted...
Thanks for your response, this seems to get me closer.
This code definitely changes the state of the button, however doing it int he Page Load is going to be hard because I haven't run the code that actually does anything with the databsa yet. Its almost like I need to manually set this to true and false through
the client code you've provided. This code defintiely changes the state but I might need a more manual solution? Do you have an examples of how to set these toggle button images exactly manually?
Its possible I am doing something wrong as well... the above code does what I need it just doesn't do it based on the database. My DB code iterates through some stuff while building the page dynamically...
I don't have a full view of your code or how you build your page. Are there many togglebuttons? If you create the togglebutton at runtime, instead of setting the checkbox.checked = true; you can also use css.
at run time you can set it: this.checkeboxID.attributes.add("checked",true);
Member
2 Points
32 Posts
ToggleButton doesn't toggle when set in code
Feb 05, 2014 11:57 AM|dl0haus|LINK
I have a toggle button that works fine, applied to a CheckBox (ToggleButtonExtender). When I click it, the images change and everything works fine. I have a situation where I need to set the Checked property to true in code. When I do this, the ToggleButton doesn't reflect this change visually even though the CheckBox is "checked". How do you force this change visually to make it programmatically change its images in accordance with the state of the CheckBox?
Its as if the ToggleButton(Extender) doesn't respond to programmatic changes, only click events. How do you circumvent this?
Thanks,
-D
Participant
1322 Points
947 Posts
Re: ToggleButton doesn't toggle when set in code
Feb 05, 2014 07:46 PM|WishStar99|LINK
put the code below in your page load.
All-Star
48393 Points
12161 Posts
Re: ToggleButton doesn't toggle when set in code
Feb 05, 2014 11:04 PM|chetan.sarode|LINK
Duplicate thread - http://forums.asp.net/t/1965534.aspx?ToggleButtonExtender+doesn+t+reflect+Checked+true+in+code
Team Lead, Product Development
Approva Systems Pvt Ltd, Pune, India.
Member
2 Points
32 Posts
Re: ToggleButton doesn't toggle when set in code
Feb 06, 2014 11:14 AM|dl0haus|LINK
If my CheckBox (with the ToggleButtonExtender) is called chkSendInvitation_1_4 and the ToggleButtonExtender is called tbxSendInvitationExtender how does it relate to the above code? Also, I'm using C# (sorry for not clarifying this) although any example I can probably convert once I know how the above names in my code relate to the RegisterStartupScript code you posted...
Participant
1322 Points
947 Posts
Re: ToggleButton doesn't toggle when set in code
Feb 07, 2014 05:56 PM|WishStar99|LINK
for c#
you would do this in your page load function. the code below will register the javascript and set your checkbox to checked.
Member
2 Points
32 Posts
Re: ToggleButton doesn't toggle when set in code
Feb 12, 2014 01:14 PM|dl0haus|LINK
Thanks for your response, this seems to get me closer.
This code definitely changes the state of the button, however doing it int he Page Load is going to be hard because I haven't run the code that actually does anything with the databsa yet. Its almost like I need to manually set this to true and false through the client code you've provided. This code defintiely changes the state but I might need a more manual solution? Do you have an examples of how to set these toggle button images exactly manually?
Its possible I am doing something wrong as well... the above code does what I need it just doesn't do it based on the database. My DB code iterates through some stuff while building the page dynamically...
Thanks,
D
Participant
1322 Points
947 Posts
Re: ToggleButton doesn't toggle when set in code
Feb 13, 2014 12:40 PM|WishStar99|LINK
I don't have a full view of your code or how you build your page. Are there many togglebuttons? If you create the togglebutton at runtime, instead of setting the checkbox.checked = true; you can also use css.
at run time you can set it: this.checkeboxID.attributes.add("checked",true);