selectedIndex is lost during postbacks - ASP.NET

后端 未结 9 1893
北海茫月
北海茫月 2021-01-13 06:35

I have a list box control:




The code behind resembles:

<         


        
9条回答
  •  情书的邮戳
    2021-01-13 06:59

    It looks to me like you are creating a new eventhandler on each page load. This might be causing the problem. Why not attach the eventhandler declaratively:

    
    

    also, why not reference the control directly, instead of casting?

    protected void lbox_SelectedIndexChanged(object sender, EventArgs e)
    {
        int index = lbox.selectedIndex;
    }
    

提交回复
热议问题