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

S

Steve Hershoff

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.
 
T

Teemu Keiski

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 :)
 
M

Mark Rae [MVP]

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...?
 
S

Steve Hershoff

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.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top