views:

18

answers:

2

Hi all

I made a web part use ASP.NET. There are a listbox and two buttons on it. When you click the Button A, it would add a new item into the listbox.When clicking the Button B, it would postback the list items data. But when you click the button B, the number of listbox number becomes twice. Does anyone meet this problem before?

Best Regards,

+1  A: 

Are you adding items to the list box in your load method? You need to check if it's a Postback before adding items again:

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        // fill list box
    }
}
Codesleuth
I add the item in the Button Click Event
Yongwei Xing
Ah, of course, sorry didn't read your question fully. OK, so we're probably going to need to see some code, because it's just not that clear how we can suggest an answer. If you could edit your question and paste your button click code, it would help a lot.
Codesleuth
A: 

can you post some code samples on what is done in the post back?

just a guess - are you checking the IsPostBack flag before initalizing data related to this list box?

without seeing/understanding what you do on the post it's hard to help...

Ami