Hello,
I think I understand ViewState pretty well, but the following is giving me some troubles:
From http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/truly-understanding-viewstate.aspx
Postback controls such as dropdownlist and textbox restore their posted state (the selected item of a dropdown ist 'posted') even when ViewState is disabled, because even with ViewState disabled the control is still able to post its value
Assuming DropDownList has EnableViewState set to false, then ( according to the above quote ) when user issues a postback by selecting an item in DropDownList, the following code should result in Label1.Text displaying a value of a selected item ( thus DropDownList.SelectedValue should return a value selected by user, even if viewstate is disabled ), but instead I get an empty string:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] number = {"first","second","third"};
DropDownList1.DataSource = number;
this.DataBind();
}
if (IsPostBack)
{
Label1.Text = DropDownList1.SelectedValue; // displays empty string
// Label1.Text = DropDownList1.SelectedItem.Text; // causes an exception
// Label1.Text = DropDownList1.SelectedIndex.ToString(); // displays empty string
}
}
The author of that article appears to be an expert on the subject, so I'm assuming I'm doing something wrong?!
thanx