Solved

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

Posted on 2011-02-11
4
408 Views
Last Modified: 2012-08-13
How to get the visibilty attribute value of a panel in javascript ?
0
Comment
Question by:PeteEngineer
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now