[英]How to get at specific HTML elements of a document using C# and Hide them/Show them etc
Basically I want to load a HTML document and using controls such as multiple check boxes which will be programmed to hide, delete or show HTML elements with certain ID's. 基本上,我想加载HTML文档并使用诸如多个复选框之类的控件,这些控件将被编程为隐藏,删除或显示具有特定ID的HTML元素。 So I am thinking I would have to set an inline CSS property for visibility to: false on the ones I want to hide or delete them altogether when necessary.
因此,我想我必须将一个内联CSS属性设置为可见性:在需要隐藏或完全删除它们的那些属性上为false。
I need this so I don't have to edit my Ebay HTML templates in dreamweaver all the time, where I usually have to scroll around messy code and manually delete or add tags and their respective content. 我需要这样做,所以我不必一直在Dreamweaver中编辑我的Ebay HTML模板,通常我需要在凌乱的代码中滚动并手动删除或添加标签及其各自的内容。 Whereas I just want to create one master template in dreamweaver which has all the variations that my products have, since they are all of the same genre with slight changes here and there and I just need to enable and disable the visibility of these variants as required and copy + paste the final html.
鉴于我只想在Dreamweaver中创建一个主模板,该模板具有我的产品的所有变体,因为它们都是同一类型,并且在各处都有一些细微的变化,我只需要根据需要启用和禁用这些变体的可见性即可。并复制并粘贴最终的html。
I haven's used Windows Forms before, but tried doing this in WebForms which I do know a bit. 我以前从未使用过Windows Forms,但是我尝试在WebForms中进行此操作,我确实知道一点。 I am able to get the result that I want by wrapping any HTML elements in a
<asp:PlaceHolder></asp:PlaceHolder>
and just setting that place holders visibility to false after the associated checkbox is checked and a postback occurs, finally I add a checkbox/button control that removes all the checkboxes, including itself etc for final html. 通过将所有HTML元素包装在
<asp:PlaceHolder></asp:PlaceHolder>
,然后在选中关联的复选框并发生回发之后,将<asp:PlaceHolder></asp:PlaceHolder>
符的可见性设置为false,就可以得到所需的结果。添加一个复选框/按钮控件,以删除所有复选框,包括最终html本身的复选框。 But this method seems just like too much pain in the ass as I have to add the placeholder tags around everything that I need control over as ordinary html elements do not run at server, also webforms injects a bunch of Javascript and ViewState data so I don't have clean HTML which I can just copy after viewing the page source. 但是这种方法似乎让我非常痛苦,因为我必须在我需要控制的所有内容周围添加占位符标签,因为普通的html元素不在服务器上运行,而且webforms注入了一堆Javascript和ViewState数据,所以我不这样做没有干净的HTML,可以在查看页面源代码后复制它们。
Any tips/code that you can suggest to achieve the desired effect with the least changes required to existing HTML documents? 您能建议在对现有HTML文档进行最少更改的情况下达到预期效果的任何技巧/代码吗? Ideally I would want to load the HTML document in, have a live design preview of it and underneath have a bunch of well labelled checkboxes programmed to hide, delete or show elements with certain ID's.
理想情况下,我想将HTML文档加载到其中,对其进行实时设计预览,并在其下面有一堆标记良好的复选框,这些复选框被编程为隐藏,删除或显示具有特定ID的元素。
Thanks... 谢谢...
i think this will work for you : 我认为这将为您工作:
HtmlControl ctl = new HtmlGenericControl( "div" );
ctl.visible = false;
Have you considered using JQuery? 您是否考虑过使用JQuery? If the elements you want to show/hide have fixed IDs then this might be a quick and dirty solution.
如果要显示/隐藏的元素具有固定的ID,则这可能是一种快速而肮脏的解决方案。
<table runat="server" id="tblMain">
<tr runat="server" id="tr1">
<td runat="server" id="tdName">
dummy name
</td>
<td runat="server" id="tdSurname">
dummy surname
</td>
...
you can use tdSurname.visible = "false";
您可以使用
tdSurname.visible = "false";
or tdSurname.Style["Visibility"] = "Hidden";
或
tdSurname.Style["Visibility"] = "Hidden";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.