开发者

How to get at specific HTML elements of a document using C# and Hide them/Show them etc

开发者 https://www.devze.com 2023-02-01 00:16 出处:网络
Basically I want to load a HTML document and using controls such as multiple check boxes which will be progr开发者_StackOverflowammed to hide, delete or show HTML elements with certain ID\'s. So I am

Basically I want to load a HTML document and using controls such as multiple check boxes which will be progr开发者_StackOverflowammed to hide, delete or show HTML elements with certain ID's. 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.

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

I haven's used Windows Forms before, but tried doing this in WebForms which I do know a bit. 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. 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.

Any tips/code that you can suggest to achieve the desired effect with the least changes required to existing HTML documents? 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.

Thanks...


<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"; or tdSurname.Style["Visibility"] = "Hidden";


Take a look at the library Html Agility pack


i think this will work for you :

HtmlControl ctl = new HtmlGenericControl( "div" );
ctl.visible = false;


Have you considered using JQuery? If the elements you want to show/hide have fixed IDs then this might be a quick and dirty solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号