If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

One of the most common questions I hear is, “How do I remove or hide something on my page?” In ASP.NET, there is an easy way to hide most controls. Whether it’s an Add To Cart button or an entire Control, there is a quick and simple method to turn it off without sacrificing the ability to easily and quickly turn it back on in the future.

Here’s a quick example: (showing how to turn off a Add To Cart button):

  1. <asp:LinkButton ID=“btnAddToCart” Runat=“server” onclick=AddCart CommandName=‘<%# DataBinder.Eval(Product,"ProductID") %>‘ Visible="false">
  2.  
  3. <asp:Image BorderWidth="0" ID="imgAddToCart" runat="server" AlternateText="Add To Cart"></asp:Image>
  4.  
  5. </asp:LinkButton>

Look for Visible=”False” at the end of the first lines of code; adding Visible=”False” is all it takes to hide the visibilty of the entire button. Again, the code to add to almost any tag on the presentation layer of your site is Visible=”false”.

Alternately, you can switch it back on by either removing the code or setting False to True.