简体   繁体   English

如何使用C#获取文档的特定HTML元素并隐藏/显示它们等

[英]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.

相关问题 如何获取字符串的特定部分并将其分配给c#中的变量? - How to get specific parts of string and assign them to variables in c#? 单击 c# 和 ASP.NET 内核中的另一个按钮时如何隐藏按钮并显示它们? - How to hide buttons and show them when clicking another button in c# and ASP.NET Core? 如何使用 C# ASP.Net 从 XML 文档中获取特定 XML 元素的列表? - How to get list of specific XML elements from XML document using C# ASP.Net? 如何使用C#隐藏和显示html模板表? - how to Hide and Show a table of html Template using C#? 如何处理大量单独的 ui 命令 c#,如何获取、初始化和执行它们 - how to handle lots of separate ui commands c#, how to get them, initialize them and execute them C#XML到LINQ具有相同名称的多个元素,如何使它们保存在同一对象中 - C# XML to LINQ multiple elements with same name, how to get them to save in same object C#HTML获取所有复选框并随机按下 - C# HTML get all checkboxes and press them randomly 如何使用C#将两个列表中的元素混合并存储为另一个列表? - How can I mix elements from two list and store them is another list using C#? 使用C#计算其中包含特定字符串变量的mysql数据库行的数量并将其显示为int时出错 - Error using C# to count the number of mysql database rows with specific string varibles in them and display them as int C#如何将对象添加到列表框并使用特定文本显示它们 - C# How to adding objects to listbox and displaying them with a specific text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM