Ajax切换按钮扩展器无法正常工作

时间:2011-10-30 16:06:12

标签: c# asp.net ajax checkbox togglebutton

<asp:CheckBox ID="CheckBox1" OnCheckedChanged="CheckBox1_CheckedChanged" runat="server" Text="Toggle Visibility" AutoPostBack="true"/>

和一个Ajax切换按钮扩展器:

<ajaxToolkit:ToggleButtonExtender ID="Ext1" CheckedImageAlternateText="View" TargetControlID="CheckBox1" runat="server" CheckedImageUrl="~/Images/Others/view.png" UncheckedImageAlternateText="Hide" UncheckedImageUrl="~/Images/Others/hide.png" ImageWidth="32" ImageHeight="24" ></ajaxToolkit:ToggleButtonExtender>

但它不起作用。 页面正在加载,但默认复选框。感谢您的帮助

1 个答案:

答案 0 :(得分:-1)

你可以这样试试......

 <%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        CheckBox myCB = new CheckBox();
        myCB.ID = "myCB";
        myCB.Checked = true;
        myCB.Text = "I like ASP.NET";
        Panel1.Controls.Add(myCB);
        AjaxControlToolkit.ToggleButtonExtender myTBE = new AjaxControlToolkit.ToggleButtonExtender();
        myTBE.TargetControlID = "myCB";
        myTBE.CheckedImageUrl = "ToggleButton_Checked.gif";
        myTBE.UncheckedImageUrl = "ToggleButton_Unchecked.gif";
        myTBE.ImageHeight = 19;
        myTBE.ImageWidth = 19;
        Panel1.Controls.Add(myTBE);                         
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:Panel ID="Panel1" runat="server">            
    </asp:Panel>
    </form>
</body>
</html>