Issue with log view with first dropdown list item selection

On my ASP.NET 4.0 website that uses master pages, I turned off sitstide browsing in web.config:

<pages enableViewState="false" />

and try to turn it on only when absolutely necessary.

I had a problem with the DropDownList control (no data binding, only hard-coded elements):

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged" Width="150px" ViewStateMode="Enabled" EnableViewState="True">
        <asp:ListItem>Chocolate</asp:ListItem>
        <asp:ListItem>Strawberry</asp:ListItem>
        <asp:ListItem>Vanilla</asp:ListItem>
    </asp:DropDownList>

Although I turned on the view state for this particular control, there is a problem with selecting the first element:

enter image description here

    protected void DropDownList1_SelectedIndexChanged (object sender, EventArgs e)
    {
        TextBox1.Text = (sender as DropDownList).SelectedValue;
    }

Expected Result: Whenever "Chocolate" is selected, TextBox1 will display "Chocolate." But what I see is that TextBox1 only changes when selecting Strawberry or Vanilla. In the above example, I selected Strawberry and then Chocolate.

, DropDownList SelectedIndexChanged , .

DropDownList:

enter image description here

, , , . ( ).

.

+3
2

, <pages enableViewState="false" /> web.config ViewStateMode.

EnableViewState=false ViewStateMode.

, ViewStateMode web.config , , EnableViewState ViewStateMode Disabled .

+1

, , . . , .

protected void DropDownList1_Load(object sender, EventArgs e)
    {
        TextBox1.Text = (sender as DropDownList).Text;
    }
0

All Articles