Note that there are some explanatory texts on larger screens.

plurals
  1. POEven if DropDownList has its viestate disabled, SelectedValue should still return a value
    primarykey
    data
    text
    <p>I think I understand ViewState pretty well, but the following is giving me some troubles: </p> <p>From <em><a href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/truly-understanding-viewstate.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/truly-understanding-viewstate.aspx</a></em></p> <blockquote> <p>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</p> </blockquote> <p><br></p> <p>Assuming <em>DropDownList</em> has <em>EnableViewState</em> set to false, then ( according to the above quote ) when user issues a postback by selecting an item in <em>DropDownList</em>, the following code should result in <em>Label1.Text</em> displaying a value of a selected item ( thus <em>DropDownList.SelectedValue</em> should return a value selected by user, even if viewstate is disabled ), but instead I get an empty string:</p> <pre><code>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 } } </code></pre> <p><br></p> <p>The author of that article appears to be an expert on the subject, so I'm assuming I'm doing something wrong !?!</p> <p><br></p> <p>thanx</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload