How do I keep a control from initializing every time?

C

Carter

I have a header control at the top of my default page. On this control
there are 4 buttons, each one displays a corresponding panel.

There also is a drop down list with a list of counties. The list of
counties is filled from a dataset when the page loads. The user selects a
county, and then selects a button. Each time a button is selected, the
control reloads and the county selection is lost and is filled again, not
only taking a lot of time but losing the user's selection. How do I stop
the drop down list from loading each time? I have tried using If
ispostback, then FillCountyList, but it doesn't seem to matter. Thanks.
 
J

John Saunders

Carter said:
I have a header control at the top of my default page. On this control
there are 4 buttons, each one displays a corresponding panel.

There also is a drop down list with a list of counties. The list of
counties is filled from a dataset when the page loads. The user selects a
county, and then selects a button. Each time a button is selected, the
control reloads and the county selection is lost and is filled again, not
only taking a lot of time but losing the user's selection. How do I stop
the drop down list from loading each time? I have tried using If
ispostback, then FillCountyList, but it doesn't seem to matter. Thanks.

First of all, I suggest you reproduce a simpler version of this problem,
like a form with one dropdown and one button, which doesn't do anything.

Second, it sounds like you are refilling the DropDownList on every postback.
Your Page_Load should probably look something like this:

private void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Load your datasets
DataBind(); // Binds loaded data to all controls
}
else
{
// You shouldn't need to load anything since data were saved in
ViewState
}
}
 

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
474,266
Messages
2,571,083
Members
48,773
Latest member
Kaybee

Latest Threads

Top