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

Discussion in 'ASP .Net' started by Sky Sigal, Jul 31, 2004.

  1. Sky Sigal

    Sky Sigal Guest

    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
    Sky Sigal, Jul 31, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave

    Search Engine Impact of ASP

    Dave, Jul 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    348
  2. Scott Cadillac
    Replies:
    0
    Views:
    342
    Scott Cadillac
    Oct 25, 2003
  3. Marcin Kalicinski

    Virtual CopyFrom() method

    Marcin Kalicinski, Jun 23, 2004, in forum: C++
    Replies:
    6
    Views:
    330
    Marcin Kalicinski
    Jun 23, 2004
  4. Rich
    Replies:
    6
    Views:
    349
    Tim Mackey
    Jan 24, 2007
  5. Nicolai Stange
    Replies:
    2
    Views:
    1,015
    Nicolai Stange
    Dec 13, 2009
Loading...

Share This Page