【问题标题】:asp:Label change visible from C# and JS code at the same timeasp:标签更改同时从 C# 和 JS 代码可见
【发布时间】:2013-09-19 14:13:22
【问题描述】:

我有 asp:Label。 如何从 C# 和 js 代码中更改可见性?

可以有:

style="display: none;"

Visible="false"

如果使用第一种方式,则无法从 C# 代码中更改可见,

如果使用第二种方式,则无法从 JS 代码中更改可见。

我需要有机会同时从 C# 和 JS 代码中更改可见性。 C#:

MyPanel.Visible = true;  

JS:

 $('.MyPanel').show();

【问题讨论】:

  • 为什么?在服务器端可见意味着该事物是否甚至发送到客户端;客户端只是将其设置为隐藏。考虑到后者既可以存在又不可见,用例是什么?
  • 如果您可以在 C# 中设置可见性,那么 javscript 中的 visibility = 'hidden/visible' 应该可以满足您的目的
  • 尝试将可见性设置为document.getElementBbyId("yourId").style.display = "none";,那么应该可以设置为Visible="false";

标签: c# javascript asp.net webforms visible


【解决方案1】:

你可以用C#设置它的样式属性,然后用js改回来

MyPanel.Attributes.Add("style","display:none");

然后在客户端你可以调用你已经声明的内容。

$('.Mypanel').show(); // i'm assuing you've add a class on the 'MyPanel' element.

【讨论】:

    猜你喜欢
    • 2014-10-13
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 2011-10-19
    • 2022-12-01
    • 2013-12-11
    • 2013-12-01
    • 1970-01-01
    相关资源
    最近更新 更多