ApplyStyle, Copyfrom, Merge and Styles -- and impact on ViewState.

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top