c# - get the new selectedValue of the listBox using the OnSelectedIndexChanged event -


i have listbox in asp.net web form. onload add items listbox , add onselectedindexchanged event handler:

public void onselectedindexchanged(object sender, eventargs eventargs) {     streamwriter sw = new streamwriter(@"c:\users\me\desktop\log.txt");      sw.writeline(listbox.selectedvalue);      sw.flush();     sw.close(); } 

the stream writer can see output...

i have autopostback set true on listbox everytime select new item reloads page print out first item in list instead of item clicked on. have idea of im doing wrong?

thanks

onload runs every time page loaded. check page.ispostback make sure adding items list first time load page. i.e.

if (!page.ispostback) { fillmylistbox(); } 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

c# - SharpSVN - How to get the previous revision? -

php cli reading files and how to fix it? -