简体   繁体   English

如何从代码后面隐藏共享相同CSS类的HTML元素?

[英]How to hide HTML elements that share same CSS class from code behind?

I'm creating a wizard using an ASP.NET MultiView control. 我正在使用ASP.NET MultiView控件创建向导。 On each of the views, I have a HTML table row containing the navigation buttons for the wizard ("Previous", "Next",...). 在每个视图上,我都有一个HTML表格行,其中包含向导的导航按钮(“上一个”,“下一个”,...)。

<tr class="rowNavButtons">.. Nav buttons go here ..</tr>

On the summary view of my wizard, I have an "Edit" button that will navigate to a specific view. 在向导的摘要视图上,我有一个“编辑”按钮,它将导航到特定视图。 I would like to hide the < tr > (containing the nav buttons) when in Edit mode. 在编辑模式下,我想隐藏<tr>(包含导航按钮)。

The issue is that I have multiple instances of that Nav row in my MultiView, and I cannot assign an ID for each one of them. 问题是我在MultiView中有该Nav行的多个实例,并且无法为其分配一个ID。 They do share a CSS class. 他们确实共享一个CSS类。

Is there a way to access all of the HTML elements that share the same CSS class? 有没有办法访问共享同一CSS类的所有HTML元素? Is there another way to group HTML elements? 还有另一种方法来组合HTML元素吗?

I've already took a look at the solutions described here : I cannot use JavaScript or jQuery, and the C# solution is generating a "System.StackOverflowException" lol Also, that thread is 4 yrs old so I was hoping there might be a newer solution :) 我已经看过这里描述的解决方案:我不能使用JavaScript或jQuery,并且C#解决方案正在生成“ System.StackOverflowException”大声笑而且,该线程已经使用了4年,所以我希望可能会有一个更新的版本解决方案:)

Thanks! 谢谢!

Give that row attribute runat="server" 给该行属性runat="server"

<tr runat="server" class="rowNavButtons">.. Nav buttons go here ..</tr>

then you can access it server side. 那么您可以在服务器端访问它。 For example, assuming this is one and only such row within a View, and you need to locate it in the active View of the MultiView - you can do something like this: 例如,假设这是一个视图中的唯一一行,并且您需要在MultiView的活动视图中找到它-您可以执行以下操作:

HtmlTableRow tr = MultiView1.GetActiveView().Controls.OfType<HtmlTableRow>.Single();
tr.Visible = false;

But frankly - it's a hack. 但坦率地说-这是骇客。 Do this on client side. 在客户端执行此操作。 If you cannot use jQuery - do it in plain JS, it's not much more complicated. 如果您不能使用jQuery,请在纯JS中进行操作,这并不复杂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM