开发者

Is it possible to change a control's UpdatePanel programmatically during an event?

开发者 https://www.devze.com 2023-03-22 00:48 出处:网络
I have two UpdatePanels, UpdatePanel1 and UpdatePanel2. I am inside of a server-side event. I would like to remove a control from UpdatePanel1 and add the control to UpdatePanel2. When I attempt to d

I have two UpdatePanels, UpdatePanel1 and UpdatePanel2.

I am inside of a server-side event. I would like to remove a control from UpdatePanel1 and add the control to UpdatePanel2. When I attempt to do so I receive an Internal Server Error 500.

Something as simple as this:

siblingPane.UpdatePanel.ContentTemplateContainer.Controls.Remove(splitter);
parentPane.UpdatePanel.ContentTemplateContainer.Controls.Add(splitter);

I looked up some how-to's on adding dynamic content to an update panel, but I haven't been able to find anything mentioning this issue in this scenario. Does anyone know anything more about this? Thanks.

EDIT: I am having this issue after having the following 'events' happen on my page:

  • User-initiates action.
  • I respond to the action client-side calling a __doPostBack targeting a control.
  • That control has implemented IPostBackEventHandler. I am now inside of RaisePostBackEvent
  • Control t开发者_如何学Gohat is responding to the postback has the hierarchy described/shown here
  • When this postback finishes the state of the web page needs to be modified such that the deletion of some controls has occurred and, in some scenarios, other controls are moved up the DOM hierarchy to a parent UpdatePanel.

I do not want to cause a full-page post-back after my __doPostBack, that would defeat the purpose of everything. I do not have the ability to change the structure of my controls during Page_Init because the controls RaisePostBackEvent is where I do all the heavy work.


The server error probably says something about not being allowed to modify the controls collection? Generally speaking, controls should be added/removed during the OnInit() (maybe it's the OnPreInit()?) part of the page lifecycle.

0

精彩评论

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