开发者

How to hide server control in JavaScript

开发者 https://www.devze.com 2023-01-18 09:21 出处:网络
Dear All, I want to hide server control in JavaScript. I do not want to use \"none\". Are there any oth开发者_StackOverflower ways to hide the control?It is not possible to hide server controls in Jav

Dear All, I want to hide server control in JavaScript. I do not want to use "none". Are there any oth开发者_StackOverflower ways to hide the control?


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.)


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();


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 );
0

精彩评论

暂无评论...
验证码 换一张
取 消