开发者

Dynamic Controls and Postback

开发者 https://www.devze.com 2023-02-19 12:11 出处:网络
I have a Panel. Now in that panel, i\'m adding controls. It is getting added and displayed.The problem is when the page is posted back.I know the controls have to be binded again in the panel. But let

I have a Panel. Now in that panel, i'm adding controls. It is getting added and displayed.The problem is when the page is posted back.I know the controls have to be binded again in the panel. But lets say if the user has entered some value in the dynamic created text box. I开发者_StackOverflowts is getting lost..


I have done this before by storing the data from the controls in session.

Every time you dynamically add a control, store the current data entered into the controls in session or viewstate for example, and then rebind on postback. Not the most elegant solution but it worked. I take it this is a webforms question?

  1. Add dynamic control click
  2. Save current form data
  3. On page_load load the data from viewstate into the controls


Make sure that the controls get the same ID each time (for ex. by specifying an ID explicitly) and you should add the dynamic controls on Page.Init so they can participate in the page's life-cycle.

There's an article on 4guysfromrolla.com, Dynamic Web Controls, Postbacks, and View State

0

精彩评论

暂无评论...
验证码 换一张
取 消