c# - Listbox causing a separate postback for the textbox -


step replicate problem

first, type in text in textbox not type enter. then, select different index in listbox. finally, view both id ( listbox , textbox ) show @ eventtarget.

expected result 1 id show @ eventtarget, 1 initialize = listbox onselected index change.

here's code:

<textbox id="textbox1" runat="server" autopostback="true"></asp:textbox> <listbox id="listbox1" runat="server" autopostback="true" onselectedindexchanged="listbox1_selectedindexchanged"> <asp:listitem text="0" value="0"></asp:listitem> <asp:listitem text="1" value="1"></asp:listitem> <asp:listitem text="2" value="2"></asp:listitem> </listbox> protected void page_load(object sender, eventargs e){ if (ispostback) { string target = request["__eventtarget"] string; system.windows.forms.messagebox.show("__eventtarget: " + target); } } protected void listbox1_selectedindexchanged(object sender, eventargs e) { }

if text box has autopostback property set true, text box cause postback when loses focus. design. see docs.

therefore, getting id of text box there expected behavior. if don't want that, consider not setting text box autopostback property true.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -