Hide tag but leave contents in rendered HTML?

Discussion in 'ASP.NET 2.0' started by JerSchneid, Mar 12, 2007.

  1. Hey guys,

    This seems like a pretty basic problem, but i don't have an answer!

    Is it possible to hide a tag in ASP.NET but still show the contents.

    For example, I have something like:

    <a runat='server' id='myLink' href='/'>This is the content!</a>

    Is it possible to render the text, but not the actual tag to the rendered HTML?

    If I just do myLink.Visible = false, it hides the content as well.
     
  2. Ok, I found a solution to my specific problem, but I don't think there is a more general solution for the built in controls.

    My specific problem is that on some of my pages I wanted to include <form> tags that post to other sites, but in my master page file I have <form runat='server'> tag that always posts back. I wanted the ability to not render that top level form tag for some pages, but still use the same master page file.

    My solution was create a new 'GhostForm' class that derives from the HtmlForm class. In this class I override the RenderBeginTag and RenderEndTag tags function to dynamically render based on a flag.

     
  3. Another way would be to create a placeholder object at the same level as the form, enum all objects in the form control and move them into the placeholder control. then remove the form object.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  4. I think I tried that, but it didn't fly because I had <% %> code within the form tag and it wouldn't let me mess with the Controls object for that element.
     
  5. Ahh yaI've had <% %> mess up a lot of stuff that should have "just worked"


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     

Share This Page