你如何设置"可见"从一个JavaScript函数的ASP.NET控件的属性? [英] How do you set the "Visible" property of a ASP.NET control from a Javascript function?

查看:148
本文介绍了你如何设置"可见"从一个JavaScript函数的ASP.NET控件的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bascially我想知道隐藏/显示从一个Javascript函数ASP.NET控件的最佳方法。我想我会只使用访问控制在Javascript:

Bascially I want to know the best way to hide/show an ASP.NET control from a Javascript function. I figured I would just access the control in Javascript using:

var theControl = document.getElementById("txtEditBox");

然后,只需设置控件的Visible属性设置为真/假。它似乎并不奏效,我似乎无法弄清楚如何设置可见真/假。我该怎么办呢?此外,是最好的方式来隐藏/显示从一个JavaScript函数的ASP.NET控件?

Then just set the control's Visible property to true/false. It doesn't seem to be working, I can't seem to figure out how to set "Visible" to true/false. How can I do that? Also, is that the best way to hide/show a ASP.NET control from a Javascript function?

谢谢,
杰夫

推荐答案

ASP.NET控件的可见属性决定它是否将在客户端上呈现(即发送到客户端)。如果在页面呈现它是假的,它永远不会到达客户端。

The "Visible" property of an ASP.NET control determines whether or not it will be rendered on the client (i.e. sent to the client). If it is false when the page is rendered, it will never arrive at the client.

所以,你不能在技术上,设置该控件的属性。

So, you cannot, technically, set that property of the control.

这表示,如果控制的的呈现在客户端上,因为Visible属性为true时呈现页面,则可以使用JavaScript这样便隐藏它:

That said, if the control is rendered on the client because the Visible property is true when the page is rendered, you can then hide it using javascript like this:

var theControl = document.getElementById("txtEditBox");
theControl.style.display = "none";

// to show it again:
theControl.style.display = "";

这是假设该控件的 ID 属性确实是在客户端上txtEditBox,它已经是可见的。

That assumes that the control's id attribute really is "txtEditBox" on the client and that it is already visible.

此外,是最好的方式来隐藏/显示从一个JavaScript函数的ASP.NET控件?

Also, is that the best way to hide/show a ASP.NET control from a Javascript function?

有不一定是最好的办法,尽管有一个更好的办法是使用CSS类定义:

There is not necessarily a "best" way, although one better approach is to use CSS class definitions:

.invisible { display: none; }

当你想隐藏什么,动态该类应用到元素;当你想再次显示它,将其删除。请注意,我相信这将只对其中的元素工作显示价值开始了为

When you want to hide something, dynamically apply that class to the element; when you want to show it again, remove it. Note, I believe this will only work for elements whose display value starts off as block.

这篇关于你如何设置"可见"从一个JavaScript函数的ASP.NET控件的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆