Shyju
Shyju

Reputation: 218722

How can I hide controls (not remove them from the DOM) on the server side?

I have a div with runat="server" set. I have an ASP.NET button control in my page. When this button is clicked, I want to hide the div.

Is there any other option that setting visible="false"?

I can't use that, because when I do, I can't access the element in my JavaScript since it is removed from the browser. I want to show the hidden div with JavaScript at a later point.

Upvotes: 2

Views: 1963

Answers (3)

Joel Coehoorn
Joel Coehoorn

Reputation: 415690

If that's the only thing your button does, I'd probably do it in javascript first to avoid the postback all together.

If that's not an option, then just add the style attribute to the div server-side with "display:none;" for the value.

Upvotes: 0

Matthew Flaschen
Matthew Flaschen

Reputation: 284786

Is there any other option that changing visibility to false.I cant use the visibility to false,because when i change visibility,I cant access the same in my javascript since it is removed from the browser.

This doesn't make sense. Setting the CSS visibility to hidden will not remove the element from the DOM.

Upvotes: 0

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421978

Add a display:none CSS style to the control:

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

Upvotes: 6

Related Questions