8. Advanced Controls Manipulation
Using QControlProxies to have Non-QControls Trigger Events
<< "Multiple QForms" Functionality via Custom QPanels   |   Back to Main   |   Next >>

View Source
will open in a new window
Using a QControlProxy to Receive Events
Sometimes you may want to create buttons, links or other HTML items which can "trigger" a Server or Ajax action without actually creating a control. The typical example of this is if you want to dynamically create a large number of links or buttons (e.g. in a QDataGrid or QDataRepeater) which would trigger an action, but because the link/button doesn't have any other state (e.g. you'll never want to change its value or style, or you're comfortable doing this in pure javascript), you don't want to incur the overhead of creating a whole QControl for each of these links or buttons.

The way you can do this is by creating a QControlProxy on your QForm, and having any manually created links or buttons make hard-coded RenderAsEvents() method calls to trigger your action/event.

The example below illustrates the manual creation (see the code for more information) of a list of links which makes use of a single QControlProxy to trigger our event. Notice that while there are 4 links and 4 buttons which each trigger Ajax-based Actions, there is actually only 1 QControl (which of course is the QControlProxy control itself) defined to handle all these events.

These A HREF links can take advantage of all Events defined on our proxy control by using RenderAsEvents...

Baz | Foo | Blah | Test

Same goes for any other HTML element, like buttons...

| | |