Visibility control of Panel control and its affect on data controls

Thought I would toss this out here this morning and perhaps someone else had run across the same issue and had found a good way to accomplish what I want. First let me state what I'm attempting to do and the problem that I've run into.
 GridView1 has a collection of rows in a SQL table that I want to present to the user. I've provided them the options of sorting and selecting only from the GridView control. 
Orgionally, I had created a detail view that was being presented in Edit mode and then customized the layout of the edit item template to suit my needs.  The only difficulty I ran into was being able to have dropdownlist's with values from the database being the selected value and updating back to the table when done.  I found lots of dropdownlist examples but none were inside a detailview control, databound to datasource B, select value from datasource A and updating back to datasource A.
Okay, Fine!  So, I figured I would simply do things a bit more manually; put labels, textbox's, and dropdownlist's in a table layout and populate it with values from the selected row in the gridview, allow the user to change things around and then update it back to the table. Piece of pie!.... Well, yes it was simple enought.... BUT!!!
I'd place this table and its collection of labels, textboxes, and dropdownlists in a Panel control so I could keep it out of view while the user was selecting a row in the GridView to edit.  During inital building of the pannel and the underlying controls I had left visibility on just for simplicity.  As soon as I changed the initial state of the Panel control and tested I found that the databound dropdownlist's in the Panel no longer function and were returning NULL values to the list selection.
Turn on visibiliy and the controls worked fine.
Further expanding on this with a little extra observation...
Before turning off the inital visibility state of the Panel control, I did have settings in the code to turn on and off visibility.  This was/is working fine. In other words, I was able progamiticly to turn off visibility and turn it back on again, so long as the inital state of visibility for the panel was visible. I would:
- Enter the page, see the panel control on the top with the gridview control below
- Select a row to edit and the controls in the panel would be populated with the values from the selected row
- Click on the Update or Cancel buttons and the action would be taken as selected and the Panel control would now be hidden from view.
- Then select a different row and see the Panel reappear with the controls populated from the newly selected row.
So.... question is... What is the difference in setting the visibility of the Panel control to 'False' in intial page load, versus turning off visibiliy in code after intial page load?  How would you suggest getting around  this issue.  It is just sloppy to leave the panel up there with no data in it while the user is expected to select a row.  At the same time, the detail view provides the 'keep it out of sight till needed' methodology, but lacks the flexibility I want for my data controls in the form. 
Your suggestions and comments are greatly appreciated!

6/21/2007 12:06:22 PM
📃 93655 articles.

💬 1 Replies

 Instead of setting Visible="false" hide the panel using CSS. When you set the visibility to hidden on the server, the control is not rendered into the page and so the values are null on postback.
You could use style="visibility:hidden"  or  style="display:none" to achieve what you are looking for.


Dont forget to click "Mark as Answer" on the post that helped you.
6/21/2007 2:38:45 PM