PDA

View Full Version : [OPEN] [#410] UserControl Auto-Loader & Manager



michaeld
Dec 13, 2013, 12:11 AM
Hi guys, I'm started writing a generalized UserControlManager control that can be added to a page or control that creates a bunch of hidden fields that indicate whether and which UserControls to reload on PostBack/DirectEvents/DirectMethods to reattach each UserControl's DirectEvents.

For instance, you manually manage this in your example here, http://examples2.ext.net/#/XRender/UserControl/UpdateContent/. You also do this in other samples which indicates to me that there is a real need for this in ext.net and that I shouldn't have to roll-my-own.

If you continue this model for dozens of user controls, you'd have to write the client-side logic to manage each and every control. Ideally, my feature request is to build this into ext.net. It would be easier to simply call a method in ResourceManager like RegisterUserControl() or similar, and have the the registered UserControls automatically load each time in post-back to the appropriate parent. We'd also need a method to unregister controls or clear them.

Scoping to the page would be easy if ResourceManager automatically generated a unique key in a hidden field on every get request upon the first call to RegisterUserControl(). A NewGuid should do the trick. Post would use this key for referencing.

Additionally there might be security concerns related to what could/should be stored in the hidden field as the user control's name or even a mapped reference could allow a savvy hacker to cross-site replace the UserControl with another if its just pure-text. However, that is easily addressed by encrypting the reference ids based on the unique key scoped to the page, and ensuring that another half of the key is stored in web.config on the server which the hacker could never gain access to.

An example of the pure text (pre-encryption) for the UserControl hidden field might contain "~/UserControl1.ascx;ParentCtrl;uc1;Static;None" where the split(';') references the control name, the parent control id to add to, the id of the UserControl, the idmode of the rendered control, and whether to rerender/updatecontent of the loaded control. There might be more but I'm just thinking out-loud here. Registering should be allowed manually or automatically by setting a bool attribute AutoRegisterUserControl to UserControlRendererConfig and UserControlLoader and other related ext.net control loader api.

This just seems very natural to me that ext.net should have a way to manage the developer's loaded UserControl resources without being forced to constantly recreate their own logic to do the same.

michaeld
Dec 18, 2013, 1:57 PM
I have implemented a non-ResourceManager implementation here.

http://forums.ext.net/showthread.php?27618-Add-UserControls-in-DirectEvents-Methods-and-have-them-automatically-Reload-on-Post-back-through-messanging-in-Hidden-Fields&p=122873#post122873 (http://forums.ext.net/showthread.php?27618-Add-UserControls-in-DirectEvents-Methods-and-have-them-automatically-Reload-on-Post-back-through-messanging-in-Hidden-Fields&p=122873#post122873)


Ideally, I'd like to see this added to Ext.Net as part of ResourceManager or Ext.Net in some appropriate way. I've done some of the leg-work and testing for proof of concept in that thread.

michaeld
Dec 23, 2013, 3:07 AM
New more reliable version posted at link above with sample test app.

Daniil
Dec 27, 2013, 5:10 AM
Thank you for the request. Created an Issue:
https://github.com/extnet/Ext.NET/issues/410

michaeld
Dec 27, 2013, 6:47 AM
Thank you for the request. Created an Issue:
https://github.com/extnet/Ext.NET/issues/410

Nice. Feel free to use any of the code I posted and tested.