Shyju
Shyju

Reputation: 218952

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: 1970

Answers (3)

Joel Coehoorn
Joel Coehoorn

Reputation: 416149

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: 285077

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: 422310

Add a display:none CSS style to the control:

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

Upvotes: 6

Related Questions