pattern for ascx control with edit and view modes

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Hi,

I want to create a number of ascx controls with edit and view modes.

Previously I have put two panels in the ascx - one for view (with label
subcontrols), and one for edit (with text box controls).

I control the visibility of the panels according to what mode the ascx is
in.

This works fine to a point - the controls in the panels share the same data
bindings, and from outside the ascx file it is nice and easy to use with
properties.

The disadvantage is some UI duplication within the 2 panels.

I don't want to use any repeater controls (like datagrid), because my data
is not repeating.

What is the design pattern for this problem?

Thanks
Martin
 
You have a couple of choices with this particular problem:

1. each view is configured as a complete object. This is what you are doing
with the panel.

2. Each bit of data is represented by two objects (one visible one hidden).

3. Each bit of data is represented by a server object that writes out
differently for each view.

4. The controls are dynamically rendered and added to the panel at runtime.

#4 is great if you are a serious heads down coder. The issue, however, is
the user control can easily become either a one size fits all mess or a
tightly coupled control (ie, it only fits one set of data due to your tests).
It works best with metadata to control output.

#3 works the best if you have reusable control patterns (ie, this is a
textbox, but in view it is a label), but requires a lot of architecture up
front to ensure you are not coupling the control to the data, ie:

a. I create a MySpecialDate textbox server control
b. I create a MyOtherTypeOfDate textbox server control

#2 works best if you can at least encapsulate the different views of a
single object in a user control (so you are back to #3 pattern with user
controls) rather than building two objects on the page for each bit of data.

#1 works best when your panels are not the same data necessarily, but,
rather, the a specific function, like PanelA = the form, PanelB = form
successfully submitted and PanelC = the form submit failed.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
3 sounds the most interesting.

Do you know where I can read more about that option?

Thanks
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top