asp.net dynamically added user control saving values after postback

前端 未结 7 818
半阙折子戏
半阙折子戏 2021-01-05 10:27

Here\'s my issue. I have a usercontrol that I want to allow users to add as many instances of as necessary using a button click (each time a button is clicked, I want to ad

相关标签:
7条回答
  • 2021-01-05 10:52

    I think what may be happening is when you click the button to add, Page_Load fires which creates you a brand new page. Then, the button click method adds the control and the page finishes rendering. When you click it the second time, Page_Load creates your page and the button click method again creates a control and adds it to the page. Unfortunately, the one you added previously is no longer there.

    What if you added the controls to a Repeater? The Repeater's view state may keep track of each control you add so that on post-back, it's not blown away.

    0 讨论(0)
提交回复
热议问题