asp.net - How can I change child controls in a composite server control on postback -
I have overall control of an asp.net web form, let's say it is control a, in which a child has overall control , Which I will call Control B. Control B's baby is dependent on control of control. a.
On initial load I am setting this parameter in the control of the control A and everything controls your child correctly in Control B setting CreateChildControls.
However, when I want to change this parameter by changing the selected index on a dropdown in the control, an event handler starts running in the lifecycle for control B. It is probably because the value is probably The CreateChildControls method of Control B has already been called.
How can I control the control of my child in such a manner that they can go through their normal lifecycle, is it necessary?
Just for clarity, when the parameters of control A are changed, control B's children may be under control, some should be removed and some should be added, so that People who still live in them still need to load the situation.
The selected index-changed event will be handled after page_load (onload) page and control A and you Thinking that your page has already been rebuilt and when you reach this event handler, consider restoring it back to the controller - as it should be, whether handling events when the page / control is still again Not made?
Three simple tips I suggest for this:
-
Do not check his parents for any value of control B. And accordingly, Build, it is a bit of an anti-pattern, instead, the correct version of Control B is loaded depending on the value of the Keep Drop Down. The IOW controls the control which is responsible for the load, not the control, B control B should be dumb and his parents should not be concerned. If he needs an interface from his guardian, then he should do it through an interface.
-
If you are just hiding and showing the field, then just place them in Control B. and hide those that should not be shown Most of the control output streams in any HTML If you set your visible asset to false, then the client has minimal impact on the page when the page is sent to the customer
-
Control is the selected value On the basis of Rebuilding some of your parts. There can be a div in it, you do a div.Controls.Clear (), and then add the right control back to it, it will be OK to do this selected index in the Chengard event, because you do not care which control already exists And what are their values (if you take care of some of the existing controls, it is relatively trivial, which is not clear from those collections and new controls around them For Odne)
Each of these three methods have pros and cons, and you can do whatever it is a mixture of all three. There is another possible way too where you use the pagerers and its GateCompamp pageInstance method to get IHttpHandler, which you use to regenerate the page, but to cover it with a small answer Has advanced.
Comments
Post a Comment