Dynamically created DropDownList loses ListItems on Postback

前端 未结 5 1989
情书的邮戳
情书的邮戳 2021-01-18 05:53

I have a page that contains some dynamically created controls (TextBox and DropDownList). When a postback occurs, the TextBoxes keep their values, but the DropDownLists lose

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-18 06:37

    A DDL will maintain its items and selection when viewstate is enabled. A textbox will maintain its contents regardless of viewstate since the resulting html is written back to the server on a postback.

    I find it courious that you have all these viewstate statements in your code and markup.

    One of several things is happening:

    1. ViewState at the control is disabled
    2. ViewState above the contrl hierachy is disabled (page, form, panel)
    3. You are dynamically adding the control too late in the page cycle for the selection to be loaded from viewstate. Loading in INIT should be fine.

提交回复
热议问题