ASP.NET how are drop down list items available after postbacks? -


i have doubt on items available in drop down list after postbacks.

i created custom web server control deriving dropdownlist:

public class statelistcontrol : dropdownlist {     public statelistcontrol()     {         this.items.add(new listitem("new york", "ny"));         this.items.add(new listitem("nebraska", "ne"));         this.items.add(new listitem("texas", "tx"));      } } 

i added control page, in page_load event did following:

protected void page_load(object sender, eventargs e) {     if (!ispostback)     {         statelistcontrol1.items.add(new listitem("michigan", "mi"));     } } 

now item added when there no postback. added button control no attached event.

now when repeatedly click button, fourth entry visible after every postback.

my doubt relates information saved drop down list has fourth item, when item added on first request , still available after repeated postbacks?

on first page load, dropdownlist populated 4 values , these stored in viewstate. when post page back, dropdownlist initialized again , values loaded viewstate. since no changes made in server side load event dropdownlist values, values remain 4 entries in viewstate.

if disable viewstate dropdown, see 3 entries available when postback, depending on whether initialize code run on every page load.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -