When you set the Visible property of a button to True, it's invisible at the server. This means it's never sent to the browser at all.
This is different from CSS's visibility property that *hides* an element while it still takes up the screen estate it would have if it was visible. To some extend, Visible in ASP.NET behaves like display: hidden in CSS where the hidden element isn't visible and doesn't take up screen estate.
However, the difference is that with CSS the code for the element is still present in the HTML, while for a server side control it isn't.
There are a few ways around this:
1. Create a table with two cells and a fixed width. Put the button in the table cells. When you hide one, the original table space stays the same, so your button stays in the same place.
2. Use CSS to move the other button. Let's say you have a Save button and a Cancel button and you want to hide the Save button:
btnSave.Visible = False
btnCancel.Attributes.Add("style", "margin-left: 75px;")
This code adds a style attribute to the Cancel button, telling it to move 75 pixels to the right. That way, it moves to the right, leaving the desired space.
Does this help?
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results
and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post