M
Mark Olbert
I have a "master" composite control which, in turn, holds an instance of a "detail" composite control (the "master" control will
ultimately contain multiple instances of the "detail" control, but I'm keeping things simple to try and figure out what's going
wrong). The master control supports databinding.
Upon postback, the detail control is not retrieving its state from ViewState after it is created and added to the master control
during the master's CreateChildControls() call. Yet if I create a separate, standalone instance of the detail control on the same
web page, the standalone instance does get properly configured from ViewState on postback. So why doesn't the instance of the detail
that's created by the master do the same thing?
Here is the definition of the master control:
[DefaultProperty("Text")]
[ToolboxData("<{0}:Survey runat=server></{0}:Survey>")]
public class Survey : CompositeControl
{
private SurveyDefinition surveyDS;
private SurveyQuestion test;
[
Bindable(true),
Category("Data"),
DefaultValue(null),
Description("The SurveyDefinition dataset to bind to"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public virtual SurveyDefinition DataSource
{
get { return surveyDS; }
set { surveyDS = value; }
}
protected override void CreateChildControls()
{
Controls.Clear();
test = new SurveyQuestion();
test.ID = "question1";
if( DataSource != null )
test.Text = DataSource.question[0].text;
Controls.Add(test);
return;
}
}
Here is the detail:
[DefaultProperty("Text")]
[ToolboxData("<{0}:SurveyQuestion runat=server></{0}:SurveyQuestion>")]
public class SurveyQuestion : CompositeControl
{
private Label lblQuestion;
public SurveyQuestion()
{
}
[
Bindable(true),
Category("Appearance"),
DefaultValue("abcd"),
Description("The question text"),
]
public string Text
{
get
{
EnsureChildControls();
return lblQuestion.Text;
}
set
{
EnsureChildControls();
lblQuestion.Text = value;
}
}
protected override void CreateChildControls()
{
Controls.Clear();
lblQuestion = new Label();
lblQuestion.ID = "lblQuestion";
Controls.Add(lblQuestion);
}
}
????
- Mark
ultimately contain multiple instances of the "detail" control, but I'm keeping things simple to try and figure out what's going
wrong). The master control supports databinding.
Upon postback, the detail control is not retrieving its state from ViewState after it is created and added to the master control
during the master's CreateChildControls() call. Yet if I create a separate, standalone instance of the detail control on the same
web page, the standalone instance does get properly configured from ViewState on postback. So why doesn't the instance of the detail
that's created by the master do the same thing?
Here is the definition of the master control:
[DefaultProperty("Text")]
[ToolboxData("<{0}:Survey runat=server></{0}:Survey>")]
public class Survey : CompositeControl
{
private SurveyDefinition surveyDS;
private SurveyQuestion test;
[
Bindable(true),
Category("Data"),
DefaultValue(null),
Description("The SurveyDefinition dataset to bind to"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public virtual SurveyDefinition DataSource
{
get { return surveyDS; }
set { surveyDS = value; }
}
protected override void CreateChildControls()
{
Controls.Clear();
test = new SurveyQuestion();
test.ID = "question1";
if( DataSource != null )
test.Text = DataSource.question[0].text;
Controls.Add(test);
return;
}
}
Here is the detail:
[DefaultProperty("Text")]
[ToolboxData("<{0}:SurveyQuestion runat=server></{0}:SurveyQuestion>")]
public class SurveyQuestion : CompositeControl
{
private Label lblQuestion;
public SurveyQuestion()
{
}
[
Bindable(true),
Category("Appearance"),
DefaultValue("abcd"),
Description("The question text"),
]
public string Text
{
get
{
EnsureChildControls();
return lblQuestion.Text;
}
set
{
EnsureChildControls();
lblQuestion.Text = value;
}
}
protected override void CreateChildControls()
{
Controls.Clear();
lblQuestion = new Label();
lblQuestion.ID = "lblQuestion";
Controls.Add(lblQuestion);
}
}
????
- Mark