Page_Load and control Persistence

G

Guest

I have a combo that gets bound to an ArrayList in Page_Load. Problem is when
user clicks on a button the page is re-loaded, however the combo's DataSource
is null. How can I get the combo to keep it's reference to the DataSource
during the re-load? I would like for the current selected item in the combo
to survive the page re-load.

private void Page_Load(object sender, System.EventArgs e)
{
if( !IsPostBack )
{
ArrayList aZips = (ArrayList) (Application["Zips"]);
cboZip.DataSource = aZips;
cboZip.DataBind();
}
}
 
G

Guest

Sorry I'm not bright. Yes I can add the arraylist to viewstate, I don't see
the difference to what I'm doing now, fetching it from Application. However
I don't get notification that the page is about to be dismissed, so how to
save the current value of the combo?

I would think that if the user clicks on a control, a button in this case,
before anything happens I'd get notified. Even at the script level.

Sudhakar Sadasivuni said:
You can add the arraylist to viewstate on pageload. and for all consequent
loads you can check for the same in ViewState and load. making objects static
also works fine but not recommended.

Sudhakar Sadasivuni
http://one.mvpblog.com
http://www.mugh.net


Coffee guy said:
I have a combo that gets bound to an ArrayList in Page_Load. Problem is when
user clicks on a button the page is re-loaded, however the combo's DataSource
is null. How can I get the combo to keep it's reference to the DataSource
during the re-load? I would like for the current selected item in the combo
to survive the page re-load.

private void Page_Load(object sender, System.EventArgs e)
{
if( !IsPostBack )
{
ArrayList aZips = (ArrayList) (Application["Zips"]);
cboZip.DataSource = aZips;
cboZip.DataBind();
}
}
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top