Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 25th, 2007, 11:55 PM
Friend of Wrox
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default Non-displacement of controls when visible="false"

I'm not sure if this is a pro topic or beginner, but I have two buttons on my page. One will always be visible, the other not. Basically, one is to view hidden content on a page (it will be a bound description of data that will appear on a click) the other button is to hide the description. So, when you click on the "show" button, you see the content and it's visible="false" and the "hide" button becomes visible"true" (and vice versa).

The problem I am trying to work out is -- How can I make the "hide" button appear where the "show" button was?

In my code for the page, I have both buttons...

<asp: button id = "show"/>
<asp: button id = "hide"/>

Is there some sort of trick or displacemenet property that VS isn't showing?


Old January 26th, 2007, 05:59 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

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?

Imar Spaanjaars
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.
Old January 26th, 2007, 06:27 PM
Friend of Wrox
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing

Thank you! I am also going to try to put the button in a form that is hidden. The form will have the appearance of a POP-UP, (as it will be absolutely positioned on the top), and it will have it's own button that will "hide" the form when clicked...Might be better to appear like a "window"....we'll see.

I really appreciate your help!


Similar Threads
Thread Thread Starter Forum Replies Last Post
certain columns of a row in datagrid visible false nanu yaru VS.NET 2002/2003 0 March 31st, 2008 08:27 AM
Can't see data from boundcolumn visible=false ipaine ASP.NET 1.x and 2.0 Application Design 1 June 20th, 2006 02:54 PM
ToolTip for Controls having Enable=False property Jim Rogers Pro VB.NET 2002/2003 5 May 3rd, 2005 02:10 PM
set rpttext box visible false myth12345 VB How-To 0 March 4th, 2005 11:08 AM
Visible property of controls in data list acko ASP.NET 1.x and 2.0 Application Design 1 December 9th, 2003 10:41 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.