473,396 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Autopostback and Listbox

Okay guys, I'll admit I'm new to asp.net but this one is shouldn't be that
difficult to fix.

I have a listbox which is populated and works fine. I have added code the
SelectedIndexChanged Event to populate a couple of textboxes with data.
Both the populating the listbox and retrieving data work fine.

Here is my problem:

Each time the SelectedIndexChanged Event is called the currently selected
item in my list box is lost. Meaning after each postback the page_load
event is fired and the index is set back to 0.

Any insight would be greatly appreciated.
Nov 18 '05 #1
3 1691
You need to put the code that loads your list box in Page_Load like
this:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack) {
// Code to populate listbox goes here
}
}

This way, the code to populate the list box will only be called the
first time a page loads - afterwards, all subsequent loads are post
back so it won't run the 2nd time.

James

Tackie wrote:
Okay guys, I'll admit I'm new to asp.net but this one is shouldn't be
that difficult to fix.

I have a listbox which is populated and works fine. I have added
code the SelectedIndexChanged Event to populate a couple of textboxes
with data. Both the populating the listbox and retrieving data work
fine.

Here is my problem:

Each time the SelectedIndexChanged Event is called the currently
selected item in my list box is lost. Meaning after each postback
the page_load event is fired and the index is set back to 0.

Any insight would be greatly appreciated.

Nov 18 '05 #2
Worked like a charm, thanks James!

"James Thomas" <Ra****@NOSPAM.gmail.com> wrote in message
news:10*************@corp.supernews.com...
You need to put the code that loads your list box in Page_Load like
this:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack) {
// Code to populate listbox goes here
}
}

This way, the code to populate the list box will only be called the
first time a page loads - afterwards, all subsequent loads are post
back so it won't run the 2nd time.

James

Tackie wrote:
Okay guys, I'll admit I'm new to asp.net but this one is shouldn't be
that difficult to fix.

I have a listbox which is populated and works fine. I have added
code the SelectedIndexChanged Event to populate a couple of textboxes
with data. Both the populating the listbox and retrieving data work
fine.

Here is my problem:

Each time the SelectedIndexChanged Event is called the currently
selected item in my list box is lost. Meaning after each postback
the page_load event is fired and the index is set back to 0.

Any insight would be greatly appreciated.

Nov 18 '05 #3
No problem, glad to be of help

Tackie wrote:
Worked like a charm, thanks James!

"James Thomas" <Ra****@NOSPAM.gmail.com> wrote in message
news:10*************@corp.supernews.com...
You need to put the code that loads your list box in Page_Load like
this:

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack) {
// Code to populate listbox goes here
}
}

This way, the code to populate the list box will only be called the
first time a page loads - afterwards, all subsequent loads are post
back so it won't run the 2nd time.

James

Tackie wrote:
Okay guys, I'll admit I'm new to asp.net but this one is
shouldn't be that difficult to fix.

I have a listbox which is populated and works fine. I have added
code the SelectedIndexChanged Event to populate a couple of
textboxes with data. Both the populating the listbox and
retrieving data work fine.

Here is my problem:

Each time the SelectedIndexChanged Event is called the currently
selected item in my list box is lost. Meaning after each postback
the page_load event is fired and the index is set back to 0.

Any insight would be greatly appreciated.


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lloyd Sheen | last post by:
I have a page that works fine. I am trying to optimize the page by overriding some of the Information that is being saved in the hidden VIEWSTATE. If I make the properties of the dropdown False...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
2
by: ben | last post by:
Hi All, I have a Listbox which gets populated from the database.On selecting an item in the list, i would like to populate some other fields......it was working fine until i added...
2
by: an | last post by:
In a ListBox I allow Multiselection. I have also the Autopostback property = True When the user wants to multiselect and presses Ctrl key and starts clicking on items, the Autopostback if...
2
by: teo | last post by:
I have a Listbox, if I set EnableViewStarte = False the AutopostaBack fired by SelectedIndexChanged doesn't work. The 'SelectedIndexChanged' event should call
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.