Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all i am having 2 check boxes and 2 div's on my web page. On checking particular check box i will show the corresponding div to the user but if i show second div the space which was occupied by first div is occupying empty space why it is happening

Assume my structure is as follows

<div id="div1"  runat="server">
<div>
</div>


XML
<div id="div2" runat="server">
<div>
</div>
</div>


<asp:checkbox id="chk1" runat="server" text="Show Div1" autopostback=true />


<asp:checkbox id="chk2" runat="server" text="Show Div2" autopostback=true />


in code i am showing as follows for both the check boxes

C#
if (chk1.Checked)
        {
            div1.Visible = true;
        }
        else
        {
            div1.Visible = false;
        }

if (chk2.Checked)
        {
            div2.Visible = true;
        }
        else
        {
            div2.Visible = false;
        }


Can any one tell how to resolve this

Sample Style applied for Div is as follows

C#
.style1
      {
          width: 268px;
          height: 19px;
          position: absolute;
          top: 16px;
          left: 335px;
          float: left;
          z-index: 1;
      }
Posted
Updated 22-Jun-11 5:38am
v3
Comments
Parwej Ahamad 22-Jun-11 12:17pm    
Can you post here parent html too which contains those div?
demouser743 23-Jun-11 1:06am    
Nothing else will be there except that in my design

1 solution

Read about it here: http://webdesign.about.com/od/css/f/blfaqhidden.htm[^]. It's a good explanation. In essence the difference is visibility leaves the space the element would take intact while the style "display:none" collapses this space.

Cheers!

--MRB
 
Share this answer
 
v2
Comments
demouser743 23-Jun-11 1:07am    
But in code how can i set visibility to true again
demouser743 24-Jun-11 4:29am    
But still i am unable to occupy the empty space even using Display:none

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900