禁用ASP .NET CheckBoxList

时间:2012-07-27 19:27:01

标签: asp.net html cross-browser internet-explorer-9 checkboxlist

我正在构建一个动态ASP表,每个单元格中都有CheckBoxLists。根据内部条件,应禁用其中一些列表。它适用于Chrome和FF,但不适用于IE9。我已经逐步执行了禁用的代码,并且Enabled属性被正确设置为false,但它无法正确呈现给IE。任何人都知道为什么?

Table optionTBL = new Table();
optionTBL.ID = "optionTBL";
TableRow headerRow = new TableRow();
TableRow listRow = new TableRow();
listRow.VerticalAlign = VerticalAlign.Top;
foreach( string[] iss in issues )
{
    // make a header
    TableHeaderCell cell = new TableHeaderCell();
    string headerTXT = "BLAH";
    cell.Text = headerTXT;
    cell.Width = Unit.Percentage( 33 );
    cell.Height = Unit.Pixel( 1 );
    cell.HorizontalAlign = HorizontalAlign.Center;
    headerRow.Cells.Add( cell );

    // put all the options in the radio list
    CheckBoxList checkLST = new CheckBoxList();
    checkLST.ID = "CKBLST" + iss[ 0 ];
    while( condition )
    {
        // build the issue radios here
        checkLST.Items.Add( new ListItem( "Text", "Value" ) );
    }

    foreach( ListItem li in checkLST.Items )
        li.Attributes.Add( "theValue", li.Value );

    // put the list in a cell in the row in the table
    TableCell cell2 = new TableCell();
    // some formatting
    checkLST.BorderColor = System.Drawing.Color.Black;
    checkLST.BorderStyle = BorderStyle.Solid;
    checkLST.BorderWidth = 1;
    checkLST.Width = Unit.Percentage( 100 );
    // here we disable the check list if needed
    if( needDisabled )
    {
        // disable the list, and check one
        checkLST.Enabled = false;
        checkLST.Items[ alreadySelected ].Selected = true;
    }
    // add the list in the cell
    cell2.Controls.Add( checkLST );
    cell2.Width = Unit.Percentage( 33 );
    // put the cell in the row
    listRow.Cells.Add( cell2 );
}

// put the table in the literal
optionTBL.Height = Unit.Percentage( 100 );
optionTBL.CellPadding = 5;
optionTBL.CssClass = "vote_table";

// here we have all the tables we need, stick em all in the literal on the page
contentPanel.Controls.Add( optionTBL );

内容面板在ASPX中如下所示,并且是标记中唯一的控件

<asp:Panel runat="server" ID="contentPanel" Height="450px" ></asp:Panel>

从IE9输出

<div style="height: 450px;" id="contentPanel">
<table style="height: 100%;" id="optionTBL" class="vote_table" border="0" cellPadding="5">
<tbody><tr>
<th style="width: 33%; height: 1px;" align="center">ballot 1<br>Select 1<br></th><th style="width: 33%; height: 1px;" align="center">ballot 2<br>Select 1<br></th>
</tr><tr vAlign="top">
<td style="width: 33%;"><table style="border: 1px solid black; width: 100%;" id="CKBLST8"" border="0">
<tbody><tr>
<td><span theValue="29"><input id="CKBLST8_0" name="CKBLST8$0" type="checkbox"><label for="CKBLST8_0">Name A</label></span></td>
</tr><tr>
<td><span theValue="30"><input id="CKBLST8_1" name="CKBLST8$1" type="checkbox"><label for="CKBLST8_1">Name B</label></span></td>
</tr><tr>
<td><span theValue="0" WWW="1"><input id="CKBLST8_2" name="CKBLST8$2" type="checkbox"><label for="CKBLST8_2"><input id="writeIn82" value="Write In Candidate" type="text"></label></span></td>
</tr>
</tbody></table></td><td style="width: 33%;"><table style="border: 1px solid black; width: 100%;" id="CKBLST9"" border="0">
<tbody><tr>
<td><span theValue="31"><input id="CKBLST9_0" name="CKBLST9$0" type="checkbox"><label for="CKBLST9_0">Name 1</label></span></td>
</tr><tr>
<td><span theValue="33"><input id="CKBLST9_1" name="CKBLST9$1" type="checkbox"><label for="CKBLST9_1">Name 2</label></span></td>
</tr><tr>
<td><span theValue="0" WWW="1"><input id="CKBLST9_2" name="CKBLST9$2" type="checkbox">   <label for="CKBLST9_2"><input id="writeIn92" value="Write In Candidate" type="text">         </label></span></td>
</tr>
</tbody></table></td>
</tr>
</tbody></table>
</div>

从chrome输出

<div id="contentPanel" style="height:450px;">
<table id="optionTBL" class="vote_table" cellpadding="5" border="0" style="height:100%;">
<tbody><tr>
<th align="center" style="height:1px;width:33%;">ballot 1<br>Select 1<br></th><th align="center" style="height:1px;width:33%;">ballot 2<br>Select 1<br></th>
</tr><tr valign="top">
<td style="width:33%;"><table id="CKBLST8" disabled="disabled" border="0" style="border-color:Black;border-width:1px;border-style:Solid;width:100%;">
<tbody><tr>
<td><span disabled="disabled" thevalue="29"><input id="CKBLST8_0" type="checkbox" name="CKBLST8$0" checked="checked" disabled="disabled"><label for="CKBLST8_0">Name A</label></span></td>
</tr><tr>
<td><span disabled="disabled" thevalue="30"><input id="CKBLST8_1" type="checkbox" name="CKBLST8$1" disabled="disabled"><label for="CKBLST8_1">Name B</label></span></td>
</tr><tr>
<td><span disabled="disabled" thevalue="0"><input id="CKBLST8_2" type="checkbox" name="CKBLST8$2" disabled="disabled"><label for="CKBLST8_2"><input type="text" id="writeIn82" value="" disabled="disabled"></label></span></td>
</tr>
</tbody></table></td><td style="width:33%;"><table id="CKBLST9" disabled="disabled" border="0" style="border-color:Black;border-width:1px;border-style:Solid;width:100%;">
<tbody><tr>
<td><span disabled="disabled" thevalue="31"><input id="CKBLST9_0" type="checkbox" name="CKBLST9$0" checked="checked" disabled="disabled"><label for="CKBLST9_0">Name 1</label></span></td>
</tr><tr>
<td><span disabled="disabled" thevalue="33"><input id="CKBLST9_1" type="checkbox" name="CKBLST9$1" disabled="disabled"><label for="CKBLST9_1">Name 2</label></span></td>
</tr><tr>
<td><span disabled="disabled" thevalue="0"><input id="CKBLST9_2" type="checkbox" name="CKBLST9$2" disabled="disabled"><label for="CKBLST9_2"><input type="text" id="writeIn92" value="" disabled="disabled"></label></span></td>
</tr>
</tbody></table></td>
</tr>
</tbody></table>
</div>

请注意,这只是ASP面板的一部分,而不是整个网页

1 个答案:

答案 0 :(得分:2)

设置属性disabled = disabled

,而不是设置属性enabled = false
li.Attributes.Add( "disabled", "disabled" );