2nd pair of eyes needed for DropDownList question & saving state

Discussion in 'ASP .Net' started by Steve Hershoff, Aug 6, 2007.

  1. Hi everyone,

    I'm not sure that what I'm trying can't be done (at least, not how I'm
    trying to do it) but I was hoping for confirmation and possible suggestions
    on a future approach.

    We have created a specialized version of the DropDownList class. An
    abbreviated version reads like this:

    public class MyDropDownList: System.Web.UI.WebControls.DropDownList
    {
    private bool _IsChanged;
    ....
    }

    The _IsChanged member is used as a "dirty" flag. Here's an overriden method
    that uses it:

    protected override void OnSelectedIndexChanged( EventArgs e )
    {
    _IsChanged = true;
    base.OnSelectedIndexChanged(e);
    }

    If I add my control to an ascx page and give it an autopostback property,
    the OnSelectedIndexChanged is fired as expected when the dropdown value
    changes.

    But modifying the _IsChanged property....does that do any good? After the
    page has been reposted I don't believe the member variable's value will be
    remembered for future use, even if viewstate has been set on the control.
    At least that's how it appears to be in this instance. (I'm using VS 2003
    for what it's worth)

    If this is the case, would you have any suggestions on how to force a
    control to remember internal values between page posts, if possible? Thanks
    very much.
    Steve Hershoff, Aug 6, 2007
    #1
    1. Advertising

  2. Steve Hershoff

    Teemu Keiski Guest

    Using ViewState for the isChanged e.g make it a property which uses
    ViewState collection under the hood. Note that when making such persistence,
    you should also think when you reset ischanged information so that it's not
    true till the end of the world when once set :)

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "Steve Hershoff" <> wrote in message
    news:...
    > Hi everyone,
    >
    > I'm not sure that what I'm trying can't be done (at least, not how I'm
    > trying to do it) but I was hoping for confirmation and possible
    > suggestions on a future approach.
    >
    > We have created a specialized version of the DropDownList class. An
    > abbreviated version reads like this:
    >
    > public class MyDropDownList: System.Web.UI.WebControls.DropDownList
    > {
    > private bool _IsChanged;
    > ....
    > }
    >
    > The _IsChanged member is used as a "dirty" flag. Here's an overriden
    > method that uses it:
    >
    > protected override void OnSelectedIndexChanged( EventArgs e )
    > {
    > _IsChanged = true;
    > base.OnSelectedIndexChanged(e);
    > }
    >
    > If I add my control to an ascx page and give it an autopostback property,
    > the OnSelectedIndexChanged is fired as expected when the dropdown value
    > changes.
    >
    > But modifying the _IsChanged property....does that do any good? After the
    > page has been reposted I don't believe the member variable's value will be
    > remembered for future use, even if viewstate has been set on the control.
    > At least that's how it appears to be in this instance. (I'm using VS 2003
    > for what it's worth)
    >
    > If this is the case, would you have any suggestions on how to force a
    > control to remember internal values between page posts, if possible?
    > Thanks very much.
    >
    Teemu Keiski, Aug 6, 2007
    #2
    1. Advertising

  3. "Steve Hershoff" <> wrote in message
    news:...

    > If this is the case, would you have any suggestions on how to force a
    > control to remember internal values between page posts, if possible?


    How are you populating the DropDownList...?


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Aug 6, 2007
    #3
  4. Hi,

    Thanks for the reply.

    I'm using a HashTable as the datasource. The property is set like this:

    public object HTSource
    {
    get{return _HTSource; }
    set
    {
    if(value is Hashtable)
    {
    _HTSource = value;
    this.DataSource = (Hashtable)_HTSource;
    }
    }
    }

    What's interesting is if I don't set the autopostback property, the
    _IsChanged value is available in subsequent postbacks. But if autopostback
    is true, it the value is available for only the auto postback and not
    subsequent postbacks. If you need more information by all means ask.



    "Mark Rae [MVP]" <> wrote in message
    news:en%...
    > "Steve Hershoff" <> wrote in message
    > news:...
    >
    >> If this is the case, would you have any suggestions on how to force a
    >> control to remember internal values between page posts, if possible?

    >
    > How are you populating the DropDownList...?
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    Steve Hershoff, Aug 6, 2007
    #4
    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. darrel
    Replies:
    0
    Views:
    339
    darrel
    Jun 21, 2004
  2. Phil Winstanley [Microsoft MVP ASP.NET]

    Re: need second pair of eyes: databinder.eval problem

    Phil Winstanley [Microsoft MVP ASP.NET], Jun 21, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    429
    darrel
    Jun 21, 2004
  3. DaLoverhino

    J2ee: need another pair of eyes.

    DaLoverhino, Nov 22, 2005, in forum: Java
    Replies:
    1
    Views:
    379
    HalcyonWild
    Nov 22, 2005
  4. =?Utf-8?B?cm9kY2hhcg==?=

    another pair of eyes...

    =?Utf-8?B?cm9kY2hhcg==?=, Jul 12, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    329
    =?Utf-8?B?cm9kY2hhcg==?=
    Jul 12, 2006
  5. Replies:
    6
    Views:
    296
    Daniel T.
    Nov 27, 2006
Loading...

Share This Page