How to change child controls in a composite server control during postback

I have an ASP.NET web form control, let it control A, which contains the child control that I will select for control B. The child controls of control B depend on the property of control A.

On boot, I set this parameter to OnLoad of control A, and everything works fine when control B correctly configures child controls in CreateChildControls.

However, when I want to change this parameter using SelectedIndexChanged in the A control drop-down list, the event handler seems to process the life cycle for B control too late to get the changed value. Presumably this is because the CreateChildControls B control method has already been called.

How can I get control B to update its child controls so that they can go through their normal life cycle, loading the viewport if necessary?

Just for clarity, when the control parameter A changes, the child controls of B may have some that remain, some that need to be removed, and some that need to be added, therefore, for those that remain, state still needs to be loaded.

+3
source share
1 answer

The SelectedIndexChanged event will be handled after the Page_Load (OnLoad) of the page and control A. And you are right in thinking that your page is already rearranged and the viewstate is restored back to the controls by the time you get to this event handler - how it should be, what it should be event handling point when the page / control has not yet been restored?

Three simple solutions that I would suggest for this:

  • B, , , , , -. A B . IOW make control , , B. Control B , . , .

  • , B , . - HTML , false, , ​​ .

  • . . DIV, div.Controls.Clear(), . SelectedIndexChanged, , ( , , , )

, , , . , PageParser GetCompiledPageInstance IHttpHandler, , , .

+4

Source: https://habr.com/ru/post/1724856/


All Articles