C# 当面板设置为显示:无时,如何将ASP面板内的控件设置为显示:无
我在控件内设置了多个面板,根据版本号显示/隐藏内容。我有代码在页面上的面板中穿行,如果版本号不匹配,则面板设置为显示:无。我知道面板设置为Display:none,因为我在调试时在Chrome开发者工具中验证了它。问题是包装在面板中的控件仍然显示在页面上。下面是如何在html中设置面板以及将面板设置为显示的代码:无。请告知。多谢各位 如果面板的visible设置为false,它就可以工作,但是我仍然需要在页面上呈现控件,即使它们没有显示C# 当面板设置为显示:无时,如何将ASP面板内的控件设置为显示:无,c#,html,panel,C#,Html,Panel,我在控件内设置了多个面板,根据版本号显示/隐藏内容。我有代码在页面上的面板中穿行,如果版本号不匹配,则面板设置为显示:无。我知道面板设置为Display:none,因为我在调试时在Chrome开发者工具中验证了它。问题是包装在面板中的控件仍然显示在页面上。下面是如何在html中设置面板以及将面板设置为显示的代码:无。请告知。多谢各位 如果面板的visible设置为false,它就可以工作,但是我仍然需要在页面上呈现控件,即使它们没有显示 <asp:Panel runat="server"
<asp:Panel runat="server" version="1" ID="property113_v1">
<tr>
<td class="asterisk"> </td>
<td colspan="2" class="required">How to blank? </td>
</tr>
<tr>
<td> </td>
<td colspan="2"><asp:RadioButtonList ID="property113" runat="server" RepeatDirection="horizontal" RepeatLayout="flow">
<asp:ListItem Text="Yes" Value="Y"></asp:ListItem>
<asp:ListItem Text="No" Value="N"></asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="property113Validator" runat="server" ControlToValidate="property113"
ErrorMessage="" Display="dynamic" ValidationGroup="Page"><span class="validator"> </span></asp:RequiredFieldValidator></td>
</tr></asp:Panel>
foreach (Panel pnl in p)
{
if (pnl.Attributes["Version"] != null)
{
if (pnl.Attributes["Version"] == ver)
{
pnl.Style.Add(HtmlTextWriterStyle.Display, "");
}
else
{
pnl.Style.Add(HtmlTextWriterStyle.Display, "none");
}
}
}
}
如何空白?
foreach(面板pnl在p中)
{
if(pnl.Attributes[“Version”!=null)
{
if(pnl.Attributes[“Version”]==版本)
{
pnl.Style.Add(HtmlTextWriterStyle.Display,“”);
}
其他的
{
pnl.Style.Add(HtmlTextWriterStyle.Display,“无”);
}
}
}
}
您的代码导致无效的html,div
不能是tr
的父级。这导致了您的问题,有关演示,请参阅:
您需要使用正确的元素tbody
更新您的aspx以使用类似的
<!-- use the tbody tag with runat=server here -->
<tbody runat="server" version="1" ID="property113_v1">
<tr>
<td class="asterisk"> </td>
<td colspan="2" class="required">How to blank? </td>
</tr>
<tr>
<td> </td>
<td colspan="2"><asp:RadioButtonList ID="property113" runat="server" RepeatDirection="horizontal" RepeatLayout="flow">
<asp:ListItem Text="Yes" Value="Y"></asp:ListItem>
<asp:ListItem Text="No" Value="N"></asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="property113Validator" runat="server" ControlToValidate="property113"
ErrorMessage="" Display="dynamic" ValidationGroup="Page"><span class="validator"> </span></asp:RequiredFieldValidator></td>
</tr></tbody>
如何空白?
现在将您的代码更新为类似以下内容:
List<HtmlGenericControl> tbodies = new List<HtmlGenericControl>{/*Populate your list here*/};
foreach (HtmlGenericControl tbody in tbodies)
{
if (tbody.Attributes["version"] != null)
{
if (tbody.Attributes["version"] == ver)
{
tbody.Style.Add(HtmlTextWriterStyle.Display, "");
} /*Probably actually don't need the else statment
else
{
pnl.Style.Add(HtmlTextWriterStyle.Display, "none");
}
*/
}
}
List tbodies=新列表{/*在此处填充您的列表*/};
foreach(HtmlGenericControl tbodies中的tbody)
{
if(tbody.Attributes[“version”!=null)
{
if(tbody.Attributes[“version”]==版本)
{
tbody.Style.Add(HtmlTextWriterStyle.Display,“”);
}/*可能实际上不需要else语句
其他的
{
pnl.Style.Add(HtmlTextWriterStyle.Display,“无”);
}
*/
}
}
您的代码导致无效的html,div
不能是tr
的父级。这导致了您的问题,有关演示,请参阅:
您需要使用正确的元素tbody
更新您的aspx以使用类似的
<!-- use the tbody tag with runat=server here -->
<tbody runat="server" version="1" ID="property113_v1">
<tr>
<td class="asterisk"> </td>
<td colspan="2" class="required">How to blank? </td>
</tr>
<tr>
<td> </td>
<td colspan="2"><asp:RadioButtonList ID="property113" runat="server" RepeatDirection="horizontal" RepeatLayout="flow">
<asp:ListItem Text="Yes" Value="Y"></asp:ListItem>
<asp:ListItem Text="No" Value="N"></asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="property113Validator" runat="server" ControlToValidate="property113"
ErrorMessage="" Display="dynamic" ValidationGroup="Page"><span class="validator"> </span></asp:RequiredFieldValidator></td>
</tr></tbody>
如何空白?
现在将您的代码更新为类似以下内容:
List<HtmlGenericControl> tbodies = new List<HtmlGenericControl>{/*Populate your list here*/};
foreach (HtmlGenericControl tbody in tbodies)
{
if (tbody.Attributes["version"] != null)
{
if (tbody.Attributes["version"] == ver)
{
tbody.Style.Add(HtmlTextWriterStyle.Display, "");
} /*Probably actually don't need the else statment
else
{
pnl.Style.Add(HtmlTextWriterStyle.Display, "none");
}
*/
}
}
List tbodies=新列表{/*在此处填充您的列表*/};
foreach(HtmlGenericControl tbodies中的tbody)
{
if(tbody.Attributes[“version”!=null)
{
if(tbody.Attributes[“version”]==版本)
{
tbody.Style.Add(HtmlTextWriterStyle.Display,“”);
}/*可能实际上不需要else语句
其他的
{
pnl.Style.Add(HtmlTextWriterStyle.Display,“无”);
}
*/
}
}
只是澄清一下-您是说带有style=“display:none”
的父项的子HTML元素是可见的?这有点难以置信。。。显示导致出现这种情况的结果HTML可能会有所帮助。请检查呈现的HTML并确保style='display:none'
实际呈现给父级div
。我还建议添加CSS类,而不是内联样式。如果不需要客户端(浏览器)与隐藏面板交互,则可以设置pnl.Visible=“false”
。注意,当前代码将导致无效HTML,这可能是问题的一部分asp:Panel
呈现一个div
,该div是tr
@AlexeiLevenkov的无效父级是的,单选按钮和td仍然显示在页面上,尽管该面板被设置为显示:无。@JonP如上所述可见=false有效,但是我需要面板内的控件仍然呈现。我选中了,并且div被设置为Display:没有,但div内没有控件?原因可能是什么?只是想澄清一下-您是说带有style=“display:none”
的父级的子HTML元素是可见的?这有点难以置信。。。显示导致出现这种情况的结果HTML可能会有所帮助。请检查呈现的HTML并确保style='display:none'
实际呈现给父级div
。我还建议添加CSS类,而不是内联样式。如果不需要客户端(浏览器)与隐藏面板交互,则可以设置pnl.Visible=“false”
。注意,当前代码将导致无效HTML,这可能是问题的一部分asp:Panel
呈现一个div
,该div是tr
@AlexeiLevenkov的无效父级是的,单选按钮和td仍然显示在页面上,尽管该面板被设置为显示:无。@JonP如上所述可见=false有效,但是我需要面板内的控件仍然呈现。我选中了,并且div被设置为Display:没有,但div内没有控件?原因可能是什么?