June 14, 2010

Render an ASP.NET Control but also Keep it Invisible




In order to hide a control, a lot of developers set the Visible property of the control to True. However what this does is that it does not Render the control, so you cannot set a value to the control.

If you want to Render the Control and also keep it invisible at the same time ‘programmatically’, use the CssStyleCollection. So for example, if you have three textboxes tbOne, tbTwo, tbThree and want to render the textbox tbTwo but keep it invisible, use the following code

tbTwo.Style.Add(HtmlTextWriterStyle.Display, "none");

What this essentially does is that it sets the display style of the textbox to none.

image

Note: You could have declared a Css class and then set the TextBox CssClass to it, but I wanted to demo an example that can be done programmatically at server side.



'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "Render an ASP.NET Control but also Keep it Invisible"
 

Copyright © 2009-2012 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions