Solved

How to get the visibilty attribute value of a panel in javascript

Posted on 2011-02-11
4
415 Views
Last Modified: 2012-08-13
How to get the visibilty attribute value of a panel in javascript ?
0
Comment
Question by:PeteEngineer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 8

Assisted Solution

by:kivan24
kivan24 earned 150 total points
ID: 34869576
<div style="display:block;" id="mypanel">PENEL</div>
<script  type="text/javascript">
var panelvis = document.getElementById('mypanel').style.display;
alert(panelvis);
</script>

Open in new window

0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 50 total points
ID: 34869691
0
 
LVL 14

Accepted Solution

by:
dejaanbu earned 200 total points
ID: 34870851
if you r trying to get visiblility property then,

<script  type="text/javascript">
var panelvis = document.getElementById('<% =thePanel.ClientID  %>').style.visibility;
alert(panelvis);
</script>

if display property then replace style.visible with style.display
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 100 total points
ID: 34871331
if the Panel is not visible .net don't generate/render the HTML so the object and its content is not in the page
So to know if the Panel is rendered or not, we may use :

 
           var Panel1 = document.getElementById("<%= Panel1.ClientID %>");
            var isVisible = (Panel1 != null); // true if visible, false else...

Open in new window

Or with jQuery :

           var isVisible = $("#<%= Panel1.ClientID %>").is(":visible");

Open in new window

           

Test page :

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
    <script language="javascript" type="text/javascript">
        $(document).ready(function() {
            //simple Javascript :
            var Panel1 = document.getElementById("<%= Panel1.ClientID %>");
            var isVisible = (Panel1 != null);
            alert(isVisible);
            // jQuery :
            isVisible = $("#<%= Panel1.ClientID %>").is(":visible");
            alert( isVisible );
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Panel runat="server" ID="Panel1" Visible="true"></asp:Panel>
    </div>
    </form>
</body>
</html>

Open in new window

0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to count occurrences of each item in an array.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question