使用 javascript 使面板可见

发布于 2024-09-27 13:23:05 字数 302 浏览 4 评论 0原文

我有一个面板,其属性 Visible 设置为 False

<asp:Panel ID="pnlUpload" runat="server" Visible="False" />

,我尝试使用 javascript 作为下面的代码使其可见

document.getElementById('<%= Panel1.ClientID %>').style.visibility = 'visible';

,但它不起作用,有什么想法吗?

I have a Panel with property, Visible set to False

<asp:Panel ID="pnlUpload" runat="server" Visible="False" />

and i try to make it visible using javascript as code below

document.getElementById('<%= Panel1.ClientID %>').style.visibility = 'visible';

but it's not working, any idea guys?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

不交电费瞎发啥光 2024-10-04 13:23:05

设置 Visible="false" 会使面板不在生成的 HTML 中呈现。如果你想让它在客户端显示/隐藏,你需要使它 Visible="true" 并使用 CSS 类/在具有“display”属性的样式属性中,其值为“block”或“none”必需的。

Setting Visible="false" makes the panel not to render in the generated HTML. If you want to make it show/hide in the client side, you need to make it Visible="true" and use a CSS class/in the style attribute having "display" property with the value "block" or "none" as required.

七度光 2024-10-04 13:23:05

我以零 ASP 经验来回答这个问题,但有很多 JS/HTML/CSS 经验,所以如果我完全错了,请耐心等待......

我会说 Visible="False" 标签不是相当于 CSS style="visibility:hidden;" 因此 JS 调用不会产生任何效果。

I am answering this with zero ASP experience but a lot of JS/HTML/CSS experience so bear with me if I am completely wrong...

I would say that the Visible="False" tag is not equivalent to the CSS style="visibility:hidden;" therefore that JS call will have no effect.

假扮的天使 2024-10-04 13:23:05

为了显示 asp 控件,您需要使用属性

ClientVisible

示例:

<asp:Panel ID="someId" runat="server" ClientInstanceName="someIdClient" ClientVisible="False" />

正如上一篇文章中提到的属性

Visible="False"

导致不渲染控件。

为了通过 Javascript 访问隐藏控件,您只需输入:

function myFunction(){ someIdClient.SetVisible(true) 

In order to display asp controls you need to use the property

ClientVisible

Example:

<asp:Panel ID="someId" runat="server" ClientInstanceName="someIdClient" ClientVisible="False" />

As mentioned in a previous post the attribute

Visible="False"

leads to not rendering the control.

In order to access the hidden control via Javascript you simply type:

function myFunction(){ someIdClient.SetVisible(true) 
人间☆小暴躁 2024-10-04 13:23:05

我尝试了 .style.visibility = 'visible' 和visible="true" 和 .style.display = 'block'
和 .style.display = 'inline' 所有这些都不起作用。
但如果你写 .style.display = 'none' 它就可以工作。
任何人都知道解决方案
请告诉我
谢谢

I tried .style.visibility = 'visible' and visible="true" and .style.display = 'block'
and .style.display = 'inline' all those thing does not work.
but if you write .style.display = 'none' it work.
any body know the solution
Please let me know
Thanks

七月上 2024-10-04 13:23:05

我的回答几乎是零 ASP 经验,例如 Flash84x :-)

似乎在 asp 中,当您设置“Visibile=false”时,不会创建面板。

如果您想使用自定义 JavaScript 而不是 .NET 工具来显示、隐藏面板,您应该直接在标签中应用样式,如下所示:

<asp:Panel id="pnlUpload" runat="server"
  Style="visibility:hidden;background-color:#CC9999; 

color:#FFFFFF;宽度:200;身高:200;
边框:实心1;填充:10">
......

然后它会在 html 中呈现类似这样的东西
:

<div id="pnlUpload" class="text" style="visibility:hidden;

背景颜色:#CC9999;颜色:#FFFFFF;宽度:200;
身高:200;边框:实心1;填充:10">
.....

</div>

当然相应的javascript是:

<script language="JavaScript">
document.getElementById('pnlUpload').style.visibility = 'visible';
</script>

I answering with almost zero ASP experience, like Flash84x :-)

It seems that in asp, when you set "Visibile=false", the panel is not created.

And if you would like to use custom JavaScript and not the .NET facility to display, hide a panel you should apply a style directly in the tag like this:

<asp:Panel id="pnlUpload" runat="server"
  Style="visibility:hidden;background-color:#CC9999; 

color:#FFFFFF; width:200; height:200;
border:solid 1; padding:10">
.....

And then it will rendere somthing like this in html
:

<div id="pnlUpload" class="text" style="visibility:hidden;

background-color:#CC9999; color:#FFFFFF; width:200;
height:200; border:solid 1; padding:10">
.....

</div>

And of course the corresponding javascript would be:

<script language="JavaScript">
document.getElementById('pnlUpload').style.visibility = 'visible';
</script>
终遇你 2024-10-04 13:23:05

请将您的面板放在 div 中
更改样式

<div>
<asp:Panel ID="pnlUpload" runat="server" Visible="False" />
</div>

并使用以下方式javascript

function visible()
{
document.getElementById('<%=pnlUpload.ClientID %>').style.display = 'block'
}

Please put your panel in a div
and change the style using the following way

<div>
<asp:Panel ID="pnlUpload" runat="server" Visible="False" />
</div>

javascript

function visible()
{
document.getElementById('<%=pnlUpload.ClientID %>').style.display = 'block'
}
寒江雪… 2024-10-04 13:23:05

不要使用可见性使用这个..

document.getElementById("<%=myPanel.ClientID%>").style.display = "none"; //not visible
document.getElementById("<%=myPanel.ClientID%>").style.display = "inline"; //visible

don't use visibility use this..

document.getElementById("<%=myPanel.ClientID%>").style.display = "none"; //not visible
document.getElementById("<%=myPanel.ClientID%>").style.display = "inline"; //visible

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文