Dear All, I want to hide server control in JavaScript. I do not want to use "none". Are there any other ways to hide the control?
A:
It is not possible to hide server controls in JavaScript. JavaScript is executed client-side, while server controls are processed server-side. JavaScript and server controls never ever communicate with each other, it is not possible.
If you would like to hide the server control, you should edit the HTML file (I don't know if this is your .aspx, .php or whatever, but I hope you understand what I mean.)
Christian Nesmark
2010-09-28 10:52:40
It is possible. A server control is just rendered to the page as a standard HTML control, so you can execute JavaScript against it as you would any other element.
GenericTypeTea
2010-09-28 10:55:33
No, in my opinion, it is strictly impossible. Of course, it is absolutely possible to hide the ACTUAL HTML that is rendered by the server control, using methods that you describe (using display:none and visibility:hidden). But when you view the source in your browser, the markup will still be there, I interpreted the question in such a way that @Aman would prefer not using CSS hiding (Quote: I do not want to user "none"), but rather stop the control from rendering server-side, using JavaScript. That is impossible - agree?
Christian Nesmark
2010-09-28 11:04:54
@Christian Nesmark - I see where you're coming from, however I understood the question as "how to hide something using JavaScript instead of using `display:none`". I'm guessing `display:none` was causing an issue, so the OP needed an alternative. But, there's obviously a language barrier that's preventing us from knowing exactly what the OP requires.
GenericTypeTea
2010-09-28 11:08:41
@GenericTypeTea: Fair enough. Maybe @Aman could enlighten us on what he really meant in his question :)
Christian Nesmark
2010-09-28 11:12:30
@Christian - I think we'll be out of luck there :)
GenericTypeTea
2010-09-28 11:44:09
A:
You can hide the server control after it's been rendered to the page. An alternative to display:none is visibility:hidden;
You could use visibility instead:
var obj = GetServerControlById(someId);
obj.style.visibility = "hidden"; // Hides
obj.style.visibility = "visible"; // Shows
If you're using ASP.Net, you can get the control via it's ClientId property:
var clientId = "<%= yourServerControl.ClientID %>";
var obj = document.getElementById(clientId );
GenericTypeTea
2010-09-28 10:53:36
A:
You can hide only HTML output generated by server-side control:
Markup:
<uc:MyControl runat="server" ID="myControl" ClientIDMode="static">
...
</uc:MyControl>
JavaScript (jQuery):
$('.myControl').hide(); // .show();
abatishchev
2010-09-28 10:56:58
@abatishchev - The OP also explicitly stated he did not want to use `none` which I guess meant he didn't want to use `display:none`, and `hide()` just sets `display:none` to the element :)
GenericTypeTea
2010-09-28 11:00:33