I have a problem that I have no idea to resolve it. In my application, I have a ViewStack with 2 children.
In the first view of the ViewStack, I have a datagrid with a XMLListCollection as dataprovider. In this view, user chooses a record from the datagrid then he passes to the second view.
In the second view, all the data chosen from the record will be loaded into different textInputs for modification.
My problem is, how can I pass these data from one view to another in ViewStack. I have done a search for the answer in this forum but no thread responses to my question.
All replies will be highly appreciated.
Thanks and best regards,
LE Hai-Binh
You can use Event handling mechanism. When you select a record in datagrid (in first child of Viewstack), create an Event object and put all the data into it and dispatch it. On the second child of Viewstack write a listener of this event. In the listener method extract the data from Event and do whatever you want to do with the it.
Related
I have editable grids which are 2-way binded to my model. What I want is to validate my data when user edits any cell before it get updated in model. I have applied my validation at ItemEditEnd handler, but, I want to apply validation in between itemEditBegin and itemEditEnd events.
any ideas how to achieve this?
For this level of validation I would create a Validator for the type of data you're editing (string, number, etc.) and set the Validator's trigger to the change event of your itemEditor component.
Check out Adobe's example on using validators in an itemEditor for more info.
Update:
You may also want to check out this related question.
"In your event listener, you can
examine the data entered into the item
editor. If the data is incorrect, you
can call the preventDefault() method
to stop Flex from passing the new data
back to the list-based control and
from closing the editor."
This is a little difficult to explain so please bear with me.
I have a procedure that is generating some radio buttons and assigning a CheckedChanged postback event based on the level being passed through (up to 4 levels). When the first level is checked (radio button selected) the postback event rb_CheckChanged00() is called and a check is done to see if this item has any children, if it does, it will create more radio buttons and assign rb_CheckChanged01 to the CheckChanged event for these - This part is working fine.
The issue I have is when I select the second Radio Button that has been created (the child), it doesn't seem to go to the post back event at all. The page is posting back when I click on it but everything resets because it won't go into rb_CheckChanged01.
I know this info is quite vague but I am hoping someone has an idea on how the post back event works and if I am somehow using it incorrectly.
Using: ASP.NET 2.0, IIS7
Thanks.
Most of the time when the dynamically created control's events are not fired, it's because the controls are 'reset' upon postback.
To make sure the same controls get created each and every time make sure that the control's IDs are set to the same values each and every time, before the ViewState is loaded. This way, when the control is added to the control collection of the page, once the ViewState is loaded, it'll persist it's properties. (just to describe what happens, in a nutshell)
One of the best articles I've read on this topic is this one. Make sure you read it, to fully understand what's happening in the background.
Looks like the child RBs are cleaned before they are able to trigger the event. From my personal experience, it's best to keep track of those dynamically generated objects, and regenerate them in every postback. The events will start to trigger :)
Your controls and events are not registered in the ViewState because dynamic controls need to be loaded in the Page_Init. Because they're not persisted in the ViewState, they won't be registered with events. A similar question:
Problem with dynamic controls in .NET
Only 1 thing can cause this, you create the rb's on page_load and don't add them to a List<> or something similar and that object to Session. What you need to do is when you create the items, Add them to a List and add that list to Session["RadioButtons"] and if the Page.IsPostBack is true, load your controls one by one from your list which is kept in your session to your page.
I am trying to manipulate (move up and down, enable/disable and launch a form) child controls inside a panel control. However I am unable to get the id of the child control on which the click event occurs.
To illustrate, I am trying to create similar functionality as is available. I am trying to create the up-down buttons that you see in the image at http://i34.tinypic.com/2gugio6.jpg
Any help/pointers are appreciated.
Thanks
I am unable to get the id of the child control on which the click event occurs.
Use event.currentTarget inside the event handler to access the child control in which the event occurred.
It would help if you post some code. Since I don't know the details, I am giving you the most basic answer.
For example, if you want id of a button in your code, you specify that id in the mxml. So,
<mx:Button label="myButton" id="btn1"/>
Now, say in your script you want to add an event listener here, you access this as
btn1.addEventListener ....
Now, lets say you want to access not a button or some independent control, but you want to access elements inside a list, there are several ways. I am presuming you would like to access the selected item. You simply say
list1.selectedItem
As I said, it would help if you post your code and specify a more precise problem.
At first glance, the Repeater control looks extremely powerful, but now I'm having second thoughts.
Problem at hand:
Adding Event Listeners to the children
Repeater object is bound to and iterates through an ArrayCollection creating new Vbox children for each item. Now for each child, the Repeater object will fire off a "repeat" event, where I'm tempted to add the eventlistener (for mouse events). No problems so far, but, what happens when the ArrayCollection changes, how should I remove the EventListeners for all the old children? Is there an array of children containing my Vbox instances that I'm skipping over in the docs? Are eventlisteners cleaned up nicely when the object they are attached to is destroyed?
-C coder lost in flex/actionscript
I would avoid using Repeaters entirely. From a performance standpoint they are very slow because the items are frequently destroyed and recreated. You are better off using a List-based control and implementing an itemRenderer.
Event listeners by default are strong references, so if you do not remove your event listeners it will prevent the object from being garbage collected. You can use the optional 5th parameter in the addEventListener called "weakReference" and set the value to true to add an event listener that will not prevent GC.
To better deal with events in your itemRender component, you can implement the IDropInListItemRenderer interface. This will give you access to "listData" which has an "owner" property which is the actual List object itself. In your itemRenderer, dispatch a custom Event containing the necessary data through the owner. If you add an event listener to the List control after it's created then you can do the event handling in the component containing the control.
Ok, seems I needed to give the vbox an id, after that I was able to access that id as an array of vboxes. After adding the event handler, I was able to use the event's currentTarget.getRepeaterItem() as a reference to the object in the ArrayCollection.
Cleaning up the event handlers was taken care of by looping over the vbox array and removing the handlers.
Not too worried about performance, as there are few items and they rarely change over the time the program is running, though those items would be different almost every run. Unless it's needlessly destroying and recreating items, it shouldn't be much of an issue.
So I'm amending someone else's code, and they've used a data-bound Accordion control. I need to disable the Accordion functionality so that the top item is expanded and the rest are just minimized and kept that way.
Also is there any way to put a class on the final item?
Thanks a lot in advance.
The easiest thing might be to replace the Accordion control with a Repeater that is styled to look like the current Accordion.
But, to attempt to answer your question(s):
Create a OnItemCommand event handler that just sets the SelectedIndex to 0. That way the user can't open any other items in the Accordion.
As far as the style of the final item, you'll have to create a OnItemDataBound event handler that knows how may items are in your collection, and then count the items that it has bound. When the method is binding an item with the index that matches the size of the collection you just set the item's CssClass to be the class for the final item. (This same technique should also work if you were to replace the Accordion with another control.)
Check the first answer for the question 'How do I bind an ASP.net ajax AccordionPane to an XMLDatasource?' for a example of the ItemDataBound event handler.