Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postback handlers does not work in composite controls #1699

Closed
Ropack opened this issue Sep 14, 2023 · 0 comments · Fixed by #1703
Closed

Postback handlers does not work in composite controls #1699

Ropack opened this issue Sep 14, 2023 · 0 comments · Fixed by #1703
Assignees
Labels

Comments

@Ropack
Copy link
Contributor

Ropack commented Sep 14, 2023

When I create a composite control, that is basically just a wrapper around button and I use that control with defined PostBack handler, that handler does not get executed when invoking button click command.

The Bootstrap button, that is also defined as composite control, is affected by the same issue. This can be easily reproduced by creating dot:Button with command binded to click and defined postback handler - this works as expected, postback handler is executed before command, but when changed to bs:Button, postback handler is not executed.

Found workaround:
In the OnPreRender method we can select the dot:Button from Children collection (possibly nested in other controls, depending on your control tree) and the call button.SetValue(PostBack.HandlersProperty, this.GetValue<PostBackHandlerCollection>(PostBack.HandlersProperty)). However, this is a bit tiresome and not intuitive for the developer.

Also it would be great if this behavior and overall design of custom controls (classic as well as composite) were better described with more examples in docs. 🙏

@exyi

@exyi exyi self-assigned this Sep 27, 2023
@exyi exyi added the bug label Sep 27, 2023
exyi added a commit that referenced this issue Sep 27, 2023
PostBack.Handlers are copied onto the created controls, if they
contain a matching command binding.

* We map postback handlers onto the command bindings set on
   the CompositeControl by comparing the EventName and property name
* For each control returned from GetContents, we enumerate its
   command bindings and compare them to the command
   bindings found on the CompositeControl.
* If a matching command binding is found, we clone its postback
   handlers onto the child control. EventName is adjusted to
   match the new property name

The control enumeration is done recursively before adding the
control to Children, thus walking only through the tree created in
this CompositeControl - nested CompositeControls,
initialized Repeaters, ... are not included.

In order to support templatws created in the CompositeControl,
we recurse into CloneTemplates. For DelegateTemplate or any
other more advanced needs, a protected
CopyPostBackHandlersRecursive method is provided.

resolves #1699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants