Dynamically created controls are wiped out on button click

后端 未结 2 1294
你的背包
你的背包 2020-12-04 00:55

I have webform where a set of controls are generated in a Panel control during a SelectedIndexChanged event of a dropdown. That all works fine.

However, when I enter

2条回答
  •  情歌与酒
    2020-12-04 01:50

    This is one of those areas where the attempt to make Webforms look like Winforms fails.

    With Webforms, you need to do the whole dance of when to create controls. I believe all your controls will need to be recreated by some time around the end of PageLoad. There might be an event or two after page load that you can use, but generally speaking PageLoad is a safe time to create controls.

    Essentially the controls need to be created before ASP.NET populates them with data from ViewState/Browser.

提交回复
热议问题