WebControl, CssStyleCollection and ViewState

Discussion in 'ASP .Net Web Controls' started by Marri Suliez, Jan 23, 2004.

  1. Marri Suliez

    Marri Suliez Guest

    Does anyone know how the Style property of the WebControl class persists
    between calls as if it's added to the ViewState? CssStyleCollection is
    not serializable.

    The following scenario leads me to believe it is being stored in
    ViewState somehow:
    1. Add a TextBox and a Button to a form
    2. Have the Button.Click event add value to the TextBox.Style collection
    3. Add a breakpoint in the Button.Click event handler immediately before
    the code in step #2 is executed
    4. Run the page
    5. Click the button
    6. When the code hits the breakpoint, note the number of TextBox.Style
    items (you'll get 4, for example)
    7. Allow the code in step #2 to run
    8. Check the number of TextBox.Style items again (you'll get 5)
    9. Click the button again
    10. Repeat step 6 and you'll get 5, leading me to believe ViewState is
    being used.

    Any ideas? Thanks.
     
    Marri Suliez, Jan 23, 2004
    #1
    1. Advertising

  2. Marri Suliez

    Teemu Keiski Guest

    Hi,

    If Style is Control's default style, created in CreateControlStyle and
    accessed via ControlStyle (and typed style members, like BackColor for
    example), it uses control's own ViewState collection to store the needed
    values. In WebControl CreateControlStyle is implemented as follows.

    protected virtual Style CreateControlStyle()
    {
    return new Style(base.ViewState);

    }

    If control exposes additional styles in addition to the ControlStyle, their
    state management needs to be done customized by overriding TrackViewState,
    oadViewState and SaveViewState methods of the control and manually
    specifying how state is tracked, loaded and saved.


    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist


    > "Marri Suliez" <> wrote in message
    > news:Xns94794EBB9822EMarriSuliezMarriSuli@24.168.128.90...
    >> Does anyone know how the Style property of the WebControl class persists
    >> between calls as if it's added to the ViewState? CssStyleCollection is
    >> not serializable.
    >>
    >> The following scenario leads me to believe it is being stored in
    >> ViewState somehow:
    >> 1. Add a TextBox and a Button to a form
    >> 2. Have the Button.Click event add value to the TextBox.Style collection
    >> 3. Add a breakpoint in the Button.Click event handler immediately before
    >> the code in step #2 is executed
    >> 4. Run the page
    >> 5. Click the button
    >> 6. When the code hits the breakpoint, note the number of TextBox.Style
    >> items (you'll get 4, for example)
    >> 7. Allow the code in step #2 to run
    >> 8. Check the number of TextBox.Style items again (you'll get 5)
    >> 9. Click the button again
    >> 10. Repeat step 6 and you'll get 5, leading me to believe ViewState is
    >> being used.
    >>
    >> Any ideas? Thanks.
     
    Teemu Keiski, Jan 23, 2004
    #2
    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. Marri Suliez
    Replies:
    1
    Views:
    2,138
    Teemu Keiski
    Jan 23, 2004
  2. Arthur Mnev
    Replies:
    0
    Views:
    538
    Arthur Mnev
    Feb 2, 2004
  3. Shawn B.

    CssStyleCollection As Property

    Shawn B., Sep 9, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    248
    Shawn B.
    Sep 15, 2003
  4. Marri Suliez

    WebControl, CssStyleCollection and ViewState

    Marri Suliez, Jan 23, 2004, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    131
    Teemu Keiski
    Jan 23, 2004
  5. Gary K

    Using CssStyleCollection (or Style class)

    Gary K, Dec 8, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    381
    Gary K
    Dec 8, 2004
Loading...

Share This Page