Return to doc.sitecore.com

7.  OnPrerender Method
Prev Next

In the OnLoad method we initialize two of our component controls and fill in their properties, but we can’t access each component control on this stage.

 

If you want to perform some extra actions with the data of the composite fields, you can do it with the OnPrerender method.

 

For example, the Custom Checklist should process every click in the checklist and fill the textbox, so an event handler should be added to every Item in the checklist.

1 protected override void OnPreRender(EventArgs e)
2       {
3          Sitecore.Shell.Applications.ContentEditor.Checklist list = FindControl(GetID("list")) as Sitecore.Shell.Applications.ContentEditor.Checklist;  
4          Sitecore.Shell.Applications.ContentEditor.Text text = FindControl(GetID("text")) as Sitecore.Shell.Applications.ContentEditor.Text;
5          FillTextBox(text, list);
6
7          if(!isEvent)
8          {
9             if(list != null)
10             {
11                for(int i = 0; i < list.Items.Length; i++ )
12                {
13                   list.Items[i].ServerProperties["Click"] = string.Format("{0}.ListItemClick", this.ID);
14                }
15             }
16          }
17
18          base.OnPreRender (e);
19       }
20
21       public void ListItemClick()
22       {
23          Sitecore.Shell.Applications.ContentEditor.Checklist list = FindControl(GetID("list")) as Sitecore.Shell.Applications.ContentEditor.Checklist;
24          Sitecore.Context.ClientPage.ClientResponse.SetReturnValue(true);
25       }

Prev Next