admin管理员组文章数量:1314320
How can I make a <asp:Panel>
visible using javascript?
I have done the following but get an error (Cannot Read property style of null)
<asp:Panel runat="server" id="panNonAfricanCountries" Visible="false">
var panNonAfricaDropDown = document.getElementById("panNonAfricanCountries")
if (dropDownFirst == "Yes") {
panNonAfricaDropDown.style.visibility = "visible";
}
How can I make a <asp:Panel>
visible using javascript?
I have done the following but get an error (Cannot Read property style of null)
<asp:Panel runat="server" id="panNonAfricanCountries" Visible="false">
var panNonAfricaDropDown = document.getElementById("panNonAfricanCountries")
if (dropDownFirst == "Yes") {
panNonAfricaDropDown.style.visibility = "visible";
}
Share
Improve this question
edited May 19, 2013 at 13:49
intuitivepixel
23.3k3 gold badges59 silver badges51 bronze badges
asked May 19, 2013 at 13:43
ArianuleArianule
9,06345 gold badges122 silver badges179 bronze badges
2
- make sure your js code run only after document load – Anoop Commented May 19, 2013 at 13:45
-
1
Have you tried
document.getElementById("<%=panNonAfricanCountries.ClientID%>")
? Or addingClientIDMode="Static"
to the control? – nnnnnn Commented May 19, 2013 at 13:47
2 Answers
Reset to default 3The Visible="false"
on an asp control have as result to not render the control on the page.
What you try to do here is to render it, but with css style to have it hidden from the user until using javascript show it. To archive that do not use the Visible, but set a style or a css to your Panel.
<asp:Panel ID="PanelId" runat="server" Visible="true" style="visibility:hidden" >
Some Content here...
</asp:Panel>
The asp.Panel
is render as div
and your html on the page will probably as:
<div id="PanelId" style="visibility:hidden">
Some Content here...
</div>
and I say probably because we do not know for sure how the Id is rendered. To get it we use the PanelId.ClientID
and your final javascript code will be:
var panNonAfricaDropDown = document.getElementById("<%=PanelId.ClientID%>");
if (dropDownFirst == "Yes" && panNonAfricaDropDown) {
panNonAfricaDropDown.style.visibility = "visible";
}
ASP.NET mangles the names of elements that run on the server. You will have to find the mangled name and then do document.getElementById on that name.
Alternatively, you can use the ClientIDMode property of asp:panel to turn off the mangling (http://msdn.microsoft./en-us/library/system.web.ui.control.clientidmode.aspx)
本文标签: htmlSetting a panel to visible using javascriptStack Overflow
版权声明:本文标题:html - Setting a panel to visible using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741889186a2403200.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论