Solved

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

Posted on 2011-02-11
4
414 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to dynamically set the form action using jQuery.

734 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