Setting the order of LoadViewState

Discussion in 'ASP .Net Building Controls' started by lisa@starways.net, Apr 8, 2005.

  1. Guest

    I have a server control. It has a Layout property, a Height property,
    and a Width property. What happens in the Height and Width property
    depends on the Layout.

    Unfortunately, what seems to be happening is that when I run a page
    that has my control in it, the Height and Width properties are
    initialized from ViewState before the Layout property. As a result,
    the Height and Width properties are assuming a Layout property of 0
    (it's an enum property, and that's what you get when there's no value).

    Is there a way that I can force my page to initialize the Layout
    property first? I've tried moving it above them in the code, on the
    chance that it's processing from the top down, but that didn't have any
    effect.

    Can anyone help?

    Thanks,
    Lisa
     
    , Apr 8, 2005
    #1
    1. Advertising

  2. Hi Lisa,

    As a best practice you should re-consider the logic or timing when events
    happen. During the LoadViewState phase you don't really want any logic to
    occur because some properties might rely on others that load their ViewState
    later. See if you can take the logic that relies on Layout and implement it
    at the PreRender event instead.

    Instead if you totally reject that idea, LoadViewState is dependent on the
    order Controls are added to the Page control tree.

    Cheers,
    Steve Goodyear
    Vancouver, Canada
     
    Steve Goodyear, Apr 8, 2005
    #2
    1. Advertising

  3. Haacked Guest

    The ViewState doesn't guarantee the order that controls
    are loaded and saved. Therefore, if the value of the
    Layout property is dependent on the Height and Width, it
    probably shouldn't be saved in the ViewState. You could
    make it a property that is calculated when it is accessed.

    If that is a problem for some reason, your best bet is to
    have your server control override the LoadViewState()
    method and load the values from the ViewState in the
    correct order. That gives you total control.

    Hope this helps.

    Phil
    http://haacked.com/

    >-----Original Message-----
    >I have a server control. It has a Layout property, a

    Height property,
    >and a Width property. What happens in the Height and

    Width property
    >depends on the Layout.
    >
    >Unfortunately, what seems to be happening is that when I

    run a page
    >that has my control in it, the Height and Width

    properties are
    >initialized from ViewState before the Layout property.

    As a result,
    >the Height and Width properties are assuming a Layout

    property of 0
    >(it's an enum property, and that's what you get when

    there's no value).
    >
    >Is there a way that I can force my page to initialize

    the Layout
    >property first? I've tried moving it above them in the

    code, on the
    >chance that it's processing from the top down, but that

    didn't have any
    >effect.
    >
    >Can anyone help?
    >
    >Thanks,
    >Lisa
    >
    >.
    >
     
    Haacked, Apr 8, 2005
    #3
    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. Showjumper
    Replies:
    0
    Views:
    4,439
    Showjumper
    Jun 26, 2003
  2. Christian
    Replies:
    0
    Views:
    415
    Christian
    Jul 16, 2003
  3. Christian
    Replies:
    0
    Views:
    395
    Christian
    Jul 17, 2003
  4. SSW

    LoadViewState

    SSW, Nov 7, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    572
  5. SSW
    Replies:
    2
    Views:
    548
Loading...

Share This Page