S
Sky Sigal
Hello:
I'm having a little trouble understanding how to effectively offer Style
control on the subelements of a Composite control.
The book I have is pointing towards a certain set of steps that appears to
save the info TWICE...but I am not sure....could someone take a look?
The steps suggested are approximately:
a) Create a webcontrol that has two inner Controls (a TextBox and Button)
b) provide public properties for each inner control's Style:
public Style StyleForInnerTextBox {
get {
if (_StyleForInnerTextBox==null){
_StyleForInnerTextBox = new Style();
if
(IsTrackingViewState){((IsTrackingViewState)StyleForInnerTextBox).TrackViewS
tate();};
}
}
public Stylle StyleForInnerButton {same thing...}
etc.
c) override the Control's LoadViewState and SaveViewState in order to save
an array of viewstates:
override object SaveViewState(){
object tBlobs = new object[2];
tBlobs[0] = base.SaveViewState();
tBlobs[1] = new
object{StyleForInnerTextBox.SaveViewState(),StyleForInnerButton.SaveViewStat
e()};
return tBlobs;
}
override void LoadViewState(object ViewState){
object[] tBlobs = ViewState;
object tOrigViewState = tBlobs[0];
object tMyExtraViewState = tBlobs[1];
base.LoadViewState[tOrigViewState];
StyleForInnerTextBox.ApplyStyle[tMyExtraViewState[0]];
StyleForInnerButton.ApplyStyle[tMyExtraViewState[1]];
}
d) In PreRender use the ApplyStyle to change the inner textbox's style:
PreRender(){
StyleForInnerTextBox.ApplyStyle(_StyleForInnerTextBox);
StyleForInnerButton.ApplyStyle(_StyleForInnerButton);
}
What worries me is that the ViewState of the InnerTextBox is being passed up
to the WebControl's viewState -- and then I am saving it again a second time
manually via the second copy (tMyExtraViewState[0]).
Therefore -- this doesn't seem right to me.
Why is it being suggested to use external Style objects -- when the
following would have worked:
public Style InnerTextBoxStyle {EnsureChildControls();return
InnerTextBox.ControlStyle;}
Thank you very very much!
Sky
I'm having a little trouble understanding how to effectively offer Style
control on the subelements of a Composite control.
The book I have is pointing towards a certain set of steps that appears to
save the info TWICE...but I am not sure....could someone take a look?
The steps suggested are approximately:
a) Create a webcontrol that has two inner Controls (a TextBox and Button)
b) provide public properties for each inner control's Style:
public Style StyleForInnerTextBox {
get {
if (_StyleForInnerTextBox==null){
_StyleForInnerTextBox = new Style();
if
(IsTrackingViewState){((IsTrackingViewState)StyleForInnerTextBox).TrackViewS
tate();};
}
}
public Stylle StyleForInnerButton {same thing...}
etc.
c) override the Control's LoadViewState and SaveViewState in order to save
an array of viewstates:
override object SaveViewState(){
object tBlobs = new object[2];
tBlobs[0] = base.SaveViewState();
tBlobs[1] = new
object{StyleForInnerTextBox.SaveViewState(),StyleForInnerButton.SaveViewStat
e()};
return tBlobs;
}
override void LoadViewState(object ViewState){
object[] tBlobs = ViewState;
object tOrigViewState = tBlobs[0];
object tMyExtraViewState = tBlobs[1];
base.LoadViewState[tOrigViewState];
StyleForInnerTextBox.ApplyStyle[tMyExtraViewState[0]];
StyleForInnerButton.ApplyStyle[tMyExtraViewState[1]];
}
d) In PreRender use the ApplyStyle to change the inner textbox's style:
PreRender(){
StyleForInnerTextBox.ApplyStyle(_StyleForInnerTextBox);
StyleForInnerButton.ApplyStyle(_StyleForInnerButton);
}
What worries me is that the ViewState of the InnerTextBox is being passed up
to the WebControl's viewState -- and then I am saving it again a second time
manually via the second copy (tMyExtraViewState[0]).
Therefore -- this doesn't seem right to me.
Why is it being suggested to use external Style objects -- when the
following would have worked:
public Style InnerTextBoxStyle {EnsureChildControls();return
InnerTextBox.ControlStyle;}
Thank you very very much!
Sky