<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" UseSubmitBehavior="false" OnClick="Button1_Click" OnClientClick="this.disabled = true; this.value = 'Submitting...'; " Text="Click Me…" /></div> <asp:DropDownList ID = "dListFruits" runat ="server" EnableViewState ="true"></asp:DropDownList> protected void Page_Load(object sender, EventArgs e) { ArrayList aList = new ArrayList(); aList.Add("Apples"); aList.Add("Oranges"); if (!Page.IsPostBack) { dListFruits.DataSource = aList; dListFruits.DataBind(); TextBox1.Text = "Hi"; } } protected void Button1_Click(object sender, EventArgs e) { }
When i had a break point in a button click event , this peice of statement “dListFruits.DataSource” shows null while debugging. I thought view state will be applied before load event triggered. But when i see the page items are appended into the dropdown list. So view state will be applied just before render?
Just check out the Items collection of the dropdownlist. Viewstate stores the items collection of dropdownlist control.