例如
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
        </asp:CheckBoxList>
我用下面的客户端代码可以控制checkboxlist是否可以使用
<script language="javascript">
     document.getElementById(CheckBoxList1).disabled=true;//或false;
</script>
但如果我在控件里加个属性 Enabled=false,即不可使用,
<asp:CheckBoxList ID="CheckBoxList1" runat="server" Enabled=false>
        </asp:CheckBoxList>
然后javascript无论怎么弄,这个控件都不能使用了,disabled=false无效了。请问:如何在加了Enabled=false属性后,仍然可以用javascript控制是否可以使用。

解决方案 »

  1.   

    如果初始设置了Enabled=false,那么最终生成的html是这样的:
    <table id="CheckBoxList1" disabled border="0">
    <tr>
    <td><span disabled><input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1:0" disabled><label for="CheckBoxList1_0">aaa</label></span></td>
    </tr>
    <tr>
    <td><span disabled><input id="CheckBoxList1_1" type="checkbox" name="CheckBoxList1:1" disabled><label for="CheckBoxList1_1">bbb</label></span></td>
    </tr>
    </table>有太多的disabled属性了!!!要一个一个地用javascript改过来~
      

  2.   

    因此,初始还是不要设置Enabled=false,如果希望首次加载控件时默认是不可用状态,那就在Page_Load里通过Page.RegisterStartupScript()输出脚本来控制吧~
      

  3.   

    谢谢Eddie005(♂) №.零零伍 (♂) 我没有使用过Page.RegisterStartupScript()。能不能小举一例子比如我有个javascript函数
    function a()
    {
    ...
    }
    如何在Page_Load里调用...哈哈偷个小懒,麻烦你了~~
      

  4.   

    Page.RegisterStartupScript("","<script>a();</script>");这就会执行a了有两点需要注意:
    <script language="javascript">
    function a()
    ....这段代码最好放在<head>部分
    第二,当需要执行两端js代码要用不同的名称
    Page.RegisterStartupScript("js1","<script>a();</script>");
    Page.RegisterStartupScript("js2","<script>b();</script>");
    如果第一个参数名称相同,那么回覆盖上一行,也就只执行b
      

  5.   

    原来是这么用的,刚才看了一下MSDN,就是看不明白那第一个参数string key到底是个什么意思,又没有什么解释
      

  6.   

    啊,我用的是.net2.0的,说page.registerstartupscript is obsolete,过时了....
    要用client.registerstartupscript...然后又多了个参数
    (Type type,String key,String script)。都不知道弄这么多干啥
      

  7.   

    Page.ClientScript.RegisterStartupScript(typeof(string), "aaa", "<script>alert(123);</script>");