Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

786 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