admin管理员组文章数量:1287652
I'm using asp(C#) under visual studio 2010
I have a panel that is by default set 2 be hidden( visible=false)
I need to create a JavaScript function that would be executed on a button click to make this panel visible if hidden and hidden if visible. and this should be client side, here is the code I have so far
<script type=text/javascript>
function func1()
{
i need this code please
}
<asp:Panel ID="ResultsPanel" runat="server">
Some controls
</asp:Panel>
<asp:button id=button1 runat=server onclick=javascript:func1()>Hide/Unhide</asp:button>
I'm using asp(C#) under visual studio 2010
I have a panel that is by default set 2 be hidden( visible=false)
I need to create a JavaScript function that would be executed on a button click to make this panel visible if hidden and hidden if visible. and this should be client side, here is the code I have so far
<script type=text/javascript>
function func1()
{
i need this code please
}
<asp:Panel ID="ResultsPanel" runat="server">
Some controls
</asp:Panel>
<asp:button id=button1 runat=server onclick=javascript:func1()>Hide/Unhide</asp:button>
Share
Improve this question
edited Feb 15, 2014 at 15:35
BenMorel
36.6k51 gold badges205 silver badges336 bronze badges
asked Sep 21, 2011 at 8:56
GhassanGhassan
3515 gold badges10 silver badges19 bronze badges
1
- If you set visible=false, the panel will not show up in your DOM, and can not be set visible later. You should have visible=true, and then hide it with CSS (style="display:none"), and then show it with one of the below solutions. – Nicolai Commented Sep 21, 2011 at 9:16
3 Answers
Reset to default 4first you need to use OnClientClick
attribute instead of OnClick
for your button, and if that button does not run any server side code you can use html button instead of asp:Button
<input type="button" onclick="func1();" value="Hide/Unhide">
you can use toggle
function in jquery
to hide/unhide your panel
function func1()
{
var mypanel = $('#<%=ResultsPanel.ClientID%>');
mypanel.toggle();
}
DEMO
Try this:
var Panel = document.getElementById("ResultsPanel");
if (Panel.style.display == "block" || Panel.style.display == "")
{
Panel.style.display = "none";
}
else
{
Panel.style.display = "block";
}
If you are using jQuery, you may make use of following jQuery methods,
http://api.jquery./toggle/
http://api.jquery./hide/
http://api.jquery./show/
本文标签: aspnetJavaScript function to hideunhide panelStack Overflow
版权声明:本文标题:asp.net - JavaScript function to hideunhide panel - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741315686a2371899.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论