使用 C# 和 ASP.NET 实现服务器端列表框可见性
我有兴趣使用“onmouseover”事件来使列表框出现和消失。 我对 ASP.NET 还很陌生,我还不想编写 javascript。 我正在尝试使用以下代码,并且它的颜色更改部分有效,但列表框可见性不起作用:
if (!IsPostBack) { Button2.Attributes.Add("onmouseover", "this.style.backgroundColor='红色', ListBox3.style.visibility='可见'"); 我
if (!IsPostBack)
{
Button2.Attributes.Add("onmouseout", "this.style.backgroundColor='Blue', ListBox3.style.visibility='hidden'");
}
已经尝试过使用和不使用“PostBack”的代码,但仍然没有运气。 有人看到我的代码哪里让我失败了吗?
谢谢你,
东风公司
I am interested in using a "onmouseover" event to make a listbox appear and disappear. I am fairly new with ASP.NET and I do not want to write javascript just yet. I am trying to use the following code, and the color change portion of it works, but the listbox visibility doesn't work:
if (!IsPostBack)
{
Button2.Attributes.Add("onmouseover", "this.style.backgroundColor='Red', ListBox3.style.visibility='visible'");
}
if (!IsPostBack)
{
Button2.Attributes.Add("onmouseout", "this.style.backgroundColor='Blue', ListBox3.style.visibility='hidden'");
}
I have tried this code with and without "PostBack", and still no luck. Does anyone see where my code is failing me?
Thank you,
DFM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
可见性属性的工作方式与显示属性略有不同。 当可见性属性设置为“隐藏”时,元素被隐藏,但布局不受影响,而当将显示属性设置为“无”时,会完全删除元素,这可能会影响布局。
如果您确实希望修改列表的可见性而不影响布局,您可以使用 div 作为包装器,然后修改其可见性属性。
修改 ASPX 以切换包含列表框的 div 元素的可见性属性。
Try:
The visibility property works a little differently than the display property. When the visibility property is set to 'hidden' the element is hidden but the layout is not affected whereas when setting display property to 'none' removes the element completely which may affect layout.
If you do wish to modify the visibility of the list without affecting the layout you can use a div as a wrapper and then modify its visibility property.
Modify the ASPX to toggle the visibility property of the div element that contains the list box.