lilith
lilith

Reputation: 1

Changing state of a radibutton with ToggleButtonExtender

I'm using ajax togglebuttonextender to set image to radibuttons. In javascript when I change the status of radibutton, togglebuttonextender status is not changed..

is there a way to set checked false of togglebuttonextender in js?

Upvotes: 0

Views: 647

Answers (2)

Shekhar
Shekhar

Reputation: 11

Call other extender's _checkChangedHandler() method on click of radio button in JavaScript.

Upvotes: 1

Bosco
Bosco

Reputation: 945

Please refer to the following example which demonstrates in javascript how to:

  • Get the state of a togglebuttonextender,
  • Change the state of a togglebuttonextender, and
  • Set the togglebuttonextender to false.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head runat="server">
            <title></title>
            <script type="text/javascript">
                function getcheckstate() {
                    var e = $find("tb");
                    alert(e._element.checked);
                }
    
                function change() {
                    var e = $find("tb");
                    e._element.click();
                    //e._element.checked = (!e._element.checked); // <--- Dont use this method because it requires you hover your mouse over the image in order for it to update.
                }
    
                function changetofalse() {
                    var e = $find("tb");
                    if (e._element.checked) e._element.click();
                }
            </script>
        </head>
        <body>
            <form id="form1" runat="server">
            <div>
                <asp:ScriptManager ID="ScriptManager1" runat="server" />
                <asp:CheckBox ID="CheckBox1" runat="server" />
                <asp:ToggleButtonExtender
                    ID="tbe"
                    TargetControlID="CheckBox1"
                    ImageWidth="22"
                    ImageHeight="22"
                    CheckedImageUrl="http://findicons.com/files/icons/1050/pidgin_old_tango_smilies/24/good.png"
                    UncheckedImageUrl="http://findicons.com/files/icons/1050/pidgin_old_tango_smilies/24/bad.png"
                    runat="server"
                    BehaviorID="tb" />
                <br /><br />
                <input type="button" onclick="getcheckstate()" value="Get Checkbox Checked State" />
                <br />
                <input type="button" onclick="change()" value="Change Checkbox Checked State" />
                <br />
                <input type="button" onclick="changetofalse()" value="Set Checkbox Checked State To False" />
            </div>
            </form>
        </body>
    </html>
    

Upvotes: 1

Related Questions