Accessing Dynamic Checkbox control's ClientID inside DataList control's OnItemCreated Event
<h2>ClientID property of Dynamic CheckBox</h2>

<h2>Problem: I need to attach some javascript function for each of checkboxes with uniqueID inside Datalist.</h2>

<p>When I'm trying to access ClientID inside <strong>OnItemCreated</strong> event in the code behind, it always resulting in the same ID which I've specified in design aspx page[It's not generating the unique ID]. Note: While It results in proper Unique ID generation when I access in <strong>OnItemDataBound</strong> command. Any reasons why?
Following is the Code...</p>

<pre><code>protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        CheckBox chk = (CheckBox)e.Item.FindControl("chkUID");
        if (chk != null)
        {
            chk.Attributes.Add("OnClick", "javascript:selectDiv(" + chk.ClientID.ToString() + ");");
        }
    } 
}
</code></pre>
