in

ASP.NET Weblogs

Dave Burke - A freelance .NET Developer specializing in Online Communities

A freelance .NET Developer

Simple approach to table, tablerow, and panel management

I do a lot of multi-table ASP.NET wizard apps, so there are typically a number of tables, tablerows or panels to manage in the course of a user going through the wizard's virtual pages.   I used to manage the visibility of elements as part of the logic of the element being populated or processed, with the elements being turned on or off depending on circumstances.  These .Visible statements were scattered throughout the .cs file and I didn't like that.

So I happened upon an approach which probably has been advocated (or maybe not because it isn't a best practice?) for a long time, but it works for me.  Essentially, I have a single method which contains all Tables, Tablerows, or Panels.  I pass to that method the table I want to turn on, or make visible.  All tables in the wizard are turned off, and before leaving the method, the active table is made visible.

private void ShowTable(HtmlTable table)
{
 tblCidForm.Visible = false;
 tblUidSelect.Visible = false;
 tblUidForm.Visible = false;
 table.Visible = true;
}

protected void FillCidForm()
{
 ShowTable(tblCidForm);
}

Published Apr 19 2004, 10:32 PM by daveburke
Filed under:

Comments

 

Brendan Tompkins said:

David,

I've struggled with this too, and I've come up with the following pattern. I store my different possible views in a View enumeration, and then call a method wich does the hide/show stuff. It works really well, and keeps all this view stuff in one place...

-Brendan

public enum ViewEnum
{
PivotTable,
PivotChart,
NotSet
}

private void ShowPanel(ViewEnum view)
{
if(m_state.CurrentView == view)
return;
else
{
this.pnlPivotChart.Visible = false;
this.pnlPivotTable.Visible = false;

switch(view)
{
case ViewEnum.PivotTable: this.pnlPivotTable.Visible = true;
break;
case ViewEnum.PivotChart:
this.pnlPivotChart.Visible = true;
break;
}
}

// Set and store the state
m_state.CurrentView = view;
m_state.StateStore(this.Session);
}
April 20, 2004 9:32 AM

Leave a Comment

(required)  
(optional)
(required)  
Add