views:

356

answers:

1

How do you set the visibility of a (fileupload) control from ASP.net code (I need to hide a fileupload control in a webuser control from server site, otherwise hasFIle is always false). Also setting the "Visible" property to false does not work (as is confuses the AJAX panel so the fileupload forgets that it has a file).

theFileUpload.Visible = false => does not work so I want to try to set the CSS style visibility to hidden or display to none.

The main problem is I want to do it from the server side (I know how I could do it on client).

Is there a safe way to overwrite

theFileUpload.Attributes["styles"]

in case I modify other CSS styles in there, also throwing a whole CSS class at it (by moidifying the CSSClass property) seems like overkill.

thanks in advance Axel

A: 

By using theFileUpload.Visible = false; you just tells to asp.net to not render theFileUpload on the page. You may use

theFileUpload.Attributes.CssStyle[HtmlTextWriterStyle.Visibility] = "hidden";

That allows you to set only a specific css property.

tanathos
Thanks, I know about that Visible=False, that simply does not render the control at all; I had settled for writing a class<style type="text/css">/*we need this to force rendering a hidden fileupload control */.hidden {display:none;}</style>and the overwriting CssClass:theFileUpload.CssClass = isVisible ? "" : "hidden";but your solutions is more elegant; need to test it though.
Axel Grude