Friday, September 4, 2009

Points to remember while creating composite controls

1. Get the ClientID of the control created and attach that ID to the child controls ID as well ClientInstanceName.

Sample Code in C#
public class NewControl : CompositeControl
{
ASPxTextBox txtTest;
protected override void CreateChildControls()
{
txtTest = new ASPxText();
txtTest.ID = "txtTest" + this.ClientID;
txtTest.ClientInstanceName = "txtTest" + this.ClientID;
txtTest.Text = “Control Initialized”;
}
}
this.Controls.Add(txtTest);
2. All controls that are interactive (i.e. not standard HTML code) created in CreateChildControls().

3. When you use popup control inside a composite control, use popup control’s Show/Popup client side events to render the controls and change contents.
strScript = cbPanelID + ".PerformCallback ('Binding');";
pcComments.ClientSideEvents.PopUp = string.Format ("function(s,e) {{{0}}}", strScript);
void cbPanel_Callback(object source, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
{
// Write codes here to perform action while loading the control
}
We are calling the Callback panels (cbPanelID) PerformCallback client side event when popup window (pcComments) populated.

No comments:

Post a Comment