High-Performance Development - C#, VB, SQL, ASP.NET

Slogan Text

This article describes how to make a web control or user control invisible on the web page, but still reside in the HTML Document Object Model (DOM).

If you set the control's attribute Visible="True" the control will not appear on the web and will not be listed in the HTML document object model. In some cases we want to use the functionality of the web control via JavaScript but we do not want the user to see the control on the web page. We'll use the CSS style attributes display and visibility to hide the web control:

<asp:button id="TimeAdd" runat="server" style="display: none;visibility: hidden;" text="Submit">
</asp:button>

You'll notice that the Button web control doesn't have a style attribute. ASP.NET will pass the attribute and value to the browser "as-is". The resulting HTML is:

<input id="TimeAdd" name="TimeAdd" onclick="javascript:__doPostBack('TimeAdd','')" style="display: none;visibility: hidden;" type="button" value="TimeAdd" />