I use both Visible="false" and display:none to hide panel, could you tell me what diffrent there are? such as speed, performance, website size..
Thanks!
<%@ 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></title>
<style type="text/css">
.myHide
{
display:none;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" Visible="false">
a1
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" CssClass="myHide">
a2
</asp:Panel>
</div>
</form></body>
</html>
SuperCool Multiple ZIP - A utility to unzip multiple files and work with multiple zip files
SuperCool Random Number Generator
![]() |
0 |
![]() |
I think the important difference lies in whether you need access to the items inside the panels, client-side. Setting visible=false will cause the panel not to be rendered, so you can't get at any of the controls, once again, client-side. Whereas if you set display none, then you will have access to the controls, as the panel is rendered.
C# <---> VB.Net Translator
![]() |
0 |
![]() |
Simplified, the hidden panel No. 2 will be rendered but just not shown up (client-side), unlike the Panel1 that will not be rendered at all (server-side).
When you ask a question, remember to click "Mark As Answer" when you get a reply which answers your question.
![]() |
0 |
![]() |
when you set visible="false" the client code for the panel does not get sent to the client, when you use display:none the equivelent code is sent to the client browser but it's display is hidden by css. try view source on the result of the above code you pasted. you should see a hidden div on the source for panel2, but for panel1 there should be no html code at all
Web Hosting Compare
![]() |
0 |
![]() |
Well, display: none entirely removes the element from the page, and the flow of the page is calculated as though the element were not there at all. On the other hand, visibility: hidden leaves the space in the document flow even though you can no longer see the element. Depending on what you are doing, that can make a huge difference or be no big deal. any way go through this.... http://www.maconstateit.net/tutorials/ASPNET20/ASPNET04/aspnet04-02.aspx
Chinna_sv...
![]() |
0 |
![]() |
Hi,
The main difference is that the Visible is offered as part of the Control base class and the display property is made to be accessible from CSS. Now if you set a server control to Visible = False it will not be rendered when IIS serves the page to the client, on the other hand if you set the panel's display style property to none the panel will indeed be render on the page markup (as a div....all asp.net panel controls are rendered as a div element) but will not be visible.
You realize this by looking at the html source code when the page is rendered.
So the only performance hit will be when rendering the page that it will need to render and generate extra html tags if the display property is set to none.
And as you might have guessed in regards to performance, speed, etc that will depend on how many children elements this panel will have....by setting the panel's visibility you are actually setting its children's visibility as well since the panel control is a container control.
Hope it helps.
Leo.
![]() |
0 |
![]() |
Thanks!
Does it mean Visible="False"have less page size and more quickly speed if Panel1 and Panel2 have the same child controls?
SuperCool Multiple ZIP - A utility to unzip multiple files and work with multiple zip files
SuperCool Random Number Generator
![]() |
0 |
![]() |
mycwcgr:
Thanks!
Does it mean Visible="False"have less page size and more quickly speed?
Yes since that part of HTML is not rendered hence you page Size will be less and in case of display none it will be rendered
Note if you are accessing your panel using client sidr scripting like javascript then you should use display none
MAK | Mark as Answer if this reply helps you | |
![]() MVP ASP/ASP.Net | ASP.Net Hosting : Host Depot | My Site : ASPSnippets |
![]() |
0 |
![]() |