SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm rendering a custom FormTemplate that includes a ListfieldIterator. How can I add an event like onclick to one of my controls rendered by the iterator?

Thanks in advance

share|improve this question
up vote 3 down vote accepted

If you want to do it in ListFieldIterator you can try the following code:

protected override void RenderChildren(System.Web.UI.HtmlTextWriter writer)
    foreach (BaseFieldControl fieldControl in SPContext.Current.FormContext.FieldControlCollection)
        if(fieldControl.Field != null && fieldControl.Field.InternalName=="BooleanFieldName")
           //attach server-side event
           ((CheckBox)fieldControl).CheckedChanged += check1_CheckChanged;
           //attach client-side event
        if(fieldControl.Field != null && fieldControl.Field.InternalName=="DateTimeFieldName")
           //attach server-side event
           ((DateTimeControl)fieldControl).DateChanged+= dateTime1_DateChanged;
           //attach client-side event
share|improve this answer
Thanks Andrew! I don't know how to explain it. But if I got you right, I can add .NET events here!? How do I add javascript events like 'onclick' here? COul u please post another piece of code? – Stefan Hennicken May 6 '13 at 14:32
For what type of control do you want to add js event? – Andrew May 6 '13 at 14:41
BooleanField-> change and DateTimeField -> onblur/lostfocus – Stefan Hennicken May 6 '13 at 14:53
I updated my answer. Hope it will help. – Andrew May 6 '13 at 15:15
Seems to be exactly what I was looking for! I'll try it now. – Stefan Hennicken May 6 '13 at 15:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.