Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
106
rated 0 times [  112] [ 6]  / answers: 1 / hits: 26087  / 10 Years ago, mon, march 24, 2014, 12:00:00

I have a asp:Panel element on my page. I'm able to set its visibility in code behind. But I need to also hide it through javascipt.



My panel is defined as following:



     <asp:Panel ID=pnlUpdateDisplay runat=server Visible=false style=width:500px; border-width: thick;>
<table style=width:300px;>
<tr>
<td valign=middle style=width:120px align=center>
<asp:Label ID=lblUpdateMessage runat=server style=position:absolute; left: 120px; top: 120px;></asp:Label>
</td>
</tr>
</table>
</asp:Panel>


When I do this:



   var panel = document.getElementById('pnlUpdateDisplay');
panel.style.visibility = 'hidden';
panel.style.display='none';


There is an error saying: Error: Unable to get value of the property 'style': object is null or undefined



Any suggestions?


More From » jquery

 Answers
40

Setting Visible=false to the server control in ascx/aspx mark up or
in a code behind prevent the control being rendered in DOM. So you
will not find them in DOM and it won't be accessible to JavaScript




Better remove Visible=false set in the panel and add style display:none.



If you want to make it in code behind follow this code



pnlUpdateDisplay.Style.Add(HtmlTextWriterStyle.Display,none);


Then use



$('#<%=pnlUpdateDisplay.ClientID %>').toggle()

[#71805] Sunday, March 23, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
neildrews

Total Points: 166
Total Questions: 103
Total Answers: 85

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
neildrews questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Tue, Oct 12, 21, 00:00, 3 Years ago
Tue, Mar 23, 21, 00:00, 3 Years ago
Sun, Aug 16, 20, 00:00, 4 Years ago
;