Wednesday, November 12, 2008

prado - attaching event handler to dynamically added control

Prado attaching event handler for a control added dynamically-

When we create a control in prado dynamically through code, we need to attach a event handler to it.
For this, control has a method 'attachEventHandler' which we can use.

For example, we create a following control

public function onPreLoad()
{
//create a control
$control = new TButton();
//attach event handler
$control.attachEventHanler('OnClick',array($this,'ButtonClicked');
//add above control
}
//event handler
public function ButtonClicked($sender,$param)
{
}//ButtonClicked

Note-
Attaching an eventHandler has to be done in method onPreLoad() otherwise if written on OnLoad method of page, eventHandler will not get called after event is invoked.



Ashwini

No comments: