C
cpnet
I have been struggling with this for a long time now, and am beginning to
think that what I'm attempting isn't the correct approach. The short
version is that I want to be able to add a webcontrol to a page, and have
that webcontrol have properties that reference other webcontrols and/or
components. These properties that reference other webcontrols or components
should be of the type of the other webcontrols or components, and their
values should be persisted. These properties should be available at design
time and run time.
The longer story is that I'm trying to develop some webcontrols/components
to implement some questionnaires. There are a few different questionnaires
(each with different questions) and they have many questions. The questions
are organized heirarchically, and the user should only be presented with a
subset of the questions from a questionnaire at any given time. My current
design has a WebControl that will be based on a TreeView
(MyNavigatorWebControl). This will act as a navigator to allow the user to
quickly jump to a particular part of the questionnaire. I'll have a
second control (MyQuestionsWebControl). This second control will display a
subset of questions with corresponding DropDownLists and validators for a
particular subset of questions from a questionnaire. Finally, I'll have a
component (MyManagerComponent). This component will be the brains behind
everything. Typically a user will place an instance each of
MyNavigatorWebControl, MyQuestionsWebControl, and MyManagerComponent on a
WebForm. The instances of MyNavigatorWebControl and, MyQuestionsWebControl
will each reference the same MyManagerComponent. MyManagerComponent will be
aware of the currently 'active' part of the questionnaire.
MyNavigatorWebControl and, MyQuestionsWebControl will use this info to know
what to display in the navigation tree, and what subset of questions to
display to the user respectively at any given time. On post backs,
MyNavigatorWebControl will inform MyManagerComponent if the user has decided
they want to view a different section of the questionnaire.
MyQuestionsWebControl will notify MyManagerComponent about answers the user
has given for the questions it was displaying. MyManagerComponent will use
the Session cache and a number of other classes to keep the whole
questionnaire's answers, associated calculations, and methods to help a
developer load and save the answers to a complete questionnaire. Basically,
MyManagerComponent holds the whole questionnaire, while my WebControls work
with MyManagerComponent to only display a small portion of the questionnaire
with each page request to keep traffic minimal.
The only way I can (sort of) getting this working is if I use DataBinding to
bind MyManagerComponent to MyNavigatorWebControl, and MyQuestionsWebControl.
However, I don't think this is really that appropriate. MyManagerComponent
is not a typical datasource that implements IEnumerable. It has a number of
complex methods that MyNavigatorWebControl, and MyQuestionsWebControl will
need to call in order to function properly. It doesn't provide a basic list
of things to display. Databinding seems to require that at design time I
deal with strings rather than actual property types when assigning my
properties. Also, if I change the MyNavigatorWebControl1.MyManagerComponent
property value at runtime, I want this change to take effect immediately,
not wait until I call DataBind.
I think part of my problem is property persistence info for WebControls is
serialized to the HTML tags in the WebForm HTML page. Component property
persistence is handled in the codebehind file for the WebForm. I need a
safe way for a WebControl property to reference an instance of a component -
at design and runtime. I suppose this may get tricky since I'm not sure
when WebControls are created in relation to components (design or run time).
The only example I've seen in MS WebControls of relating a WebControl to a
Component, is attaching a DataSource to a DataBound Control of somesort
(i.e. assigning a DataSet to a DataGrid). But again, I don't think this is
really what I need. I just want my WebControls to reference (but not 'own')
Components, so that a given Component can be shared by several WebControls,
and so that the WebControls can take advantage of not only the data, but the
functionality of the Component. Is DataBinding my only option? Is my
design flawed?
Thanks,
cpnet
think that what I'm attempting isn't the correct approach. The short
version is that I want to be able to add a webcontrol to a page, and have
that webcontrol have properties that reference other webcontrols and/or
components. These properties that reference other webcontrols or components
should be of the type of the other webcontrols or components, and their
values should be persisted. These properties should be available at design
time and run time.
The longer story is that I'm trying to develop some webcontrols/components
to implement some questionnaires. There are a few different questionnaires
(each with different questions) and they have many questions. The questions
are organized heirarchically, and the user should only be presented with a
subset of the questions from a questionnaire at any given time. My current
design has a WebControl that will be based on a TreeView
(MyNavigatorWebControl). This will act as a navigator to allow the user to
quickly jump to a particular part of the questionnaire. I'll have a
second control (MyQuestionsWebControl). This second control will display a
subset of questions with corresponding DropDownLists and validators for a
particular subset of questions from a questionnaire. Finally, I'll have a
component (MyManagerComponent). This component will be the brains behind
everything. Typically a user will place an instance each of
MyNavigatorWebControl, MyQuestionsWebControl, and MyManagerComponent on a
WebForm. The instances of MyNavigatorWebControl and, MyQuestionsWebControl
will each reference the same MyManagerComponent. MyManagerComponent will be
aware of the currently 'active' part of the questionnaire.
MyNavigatorWebControl and, MyQuestionsWebControl will use this info to know
what to display in the navigation tree, and what subset of questions to
display to the user respectively at any given time. On post backs,
MyNavigatorWebControl will inform MyManagerComponent if the user has decided
they want to view a different section of the questionnaire.
MyQuestionsWebControl will notify MyManagerComponent about answers the user
has given for the questions it was displaying. MyManagerComponent will use
the Session cache and a number of other classes to keep the whole
questionnaire's answers, associated calculations, and methods to help a
developer load and save the answers to a complete questionnaire. Basically,
MyManagerComponent holds the whole questionnaire, while my WebControls work
with MyManagerComponent to only display a small portion of the questionnaire
with each page request to keep traffic minimal.
The only way I can (sort of) getting this working is if I use DataBinding to
bind MyManagerComponent to MyNavigatorWebControl, and MyQuestionsWebControl.
However, I don't think this is really that appropriate. MyManagerComponent
is not a typical datasource that implements IEnumerable. It has a number of
complex methods that MyNavigatorWebControl, and MyQuestionsWebControl will
need to call in order to function properly. It doesn't provide a basic list
of things to display. Databinding seems to require that at design time I
deal with strings rather than actual property types when assigning my
properties. Also, if I change the MyNavigatorWebControl1.MyManagerComponent
property value at runtime, I want this change to take effect immediately,
not wait until I call DataBind.
I think part of my problem is property persistence info for WebControls is
serialized to the HTML tags in the WebForm HTML page. Component property
persistence is handled in the codebehind file for the WebForm. I need a
safe way for a WebControl property to reference an instance of a component -
at design and runtime. I suppose this may get tricky since I'm not sure
when WebControls are created in relation to components (design or run time).
The only example I've seen in MS WebControls of relating a WebControl to a
Component, is attaching a DataSource to a DataBound Control of somesort
(i.e. assigning a DataSet to a DataGrid). But again, I don't think this is
really what I need. I just want my WebControls to reference (but not 'own')
Components, so that a given Component can be shared by several WebControls,
and so that the WebControls can take advantage of not only the data, but the
functionality of the Component. Is DataBinding my only option? Is my
design flawed?
Thanks,
cpnet