0

我正在构建一个动态ASP表,每个单元格都有CheckBoxLists。基于内部条件,这些列表中的一些应该被禁用。它适用于Chrome和FF,但不适用于IE9。我介绍了正在执行禁用的代码,并将Enabled属性正确设置为false,但它无法正确呈现给IE。任何人有一个想法为什么?禁用ASP .NET CheckBoxList

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如下,是在标记的唯一控制从IE9

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

输出从铬

<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> 

输出

<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的一部分面板,而不是整个网页

+0

你能也显示在IE9所呈现的HTML禁用=属性? – 2012-07-27 20:05:29

+0

这有点奇怪。 Chrome html可以在IE9(或FF)中正常工作。那么为什么它会被IE浏览器破解?为什么'disabled ='禁用''省略? – 2012-07-27 21:23:04

回答

2

而不是设置属性的启用=假,设置禁用

li.Attributes.Add("disabled", "disabled"); 
+0

工作。我还必须添加checked ='checked'属性。另外值得注意的是,这种方法在Chrome中无法正确显示。所以在使用我的原始代码,并且这个属性方法在两者中都能正确显示。虽然我还不确定为什么,但至少现在正在工作。谢谢您的帮助! – CDspace 2012-07-30 20:26:07