Rectangle 27 0

c In ASP.NET Web Forms I want to get control inside child Repeater with javascript?


void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) 
 {
      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
      {            
          TextBox txt21 = (TextBox)e.Item.FindControl("txt21");
          RequiredFieldValidator rfv21 = (RequiredFieldValidator)e.Item.FindControl("rfv21");
          txt21.Attributes.Add("onclick", "txt21_onChange('" + txt21.ClientID + "','" + rfv21.ClientID + "'" )            
      }
 }
function txt21_onChange(txt21ID, rfv21ID) 
{
    txt21ID = document.getElementById(txt21ID);
    rfv21ID = document.getElementById(rfv21ID);
    //The above are TextBox and RequiredFieldValidator objects of row of TextBox that triggered change event.
    //You can use these object  
}

This also a good and acceptable answer, but i choose the another one because it will be more cleaner and easier to do that client side

You can bind the javascript function call from Repeater Repeater.ItemDataBound event.

Note
Rectangle 27 0

c In ASP.NET Web Forms I want to get control inside child Repeater with javascript?


function txt21_onChange(txtbox) {
    var rfv2 = 
     $(textbox)           // gives you the jquery object representing the textbox
     .closest("div")      // the parent div
     .find("id*='rfv2'"); // the element you are looking for, id contains rfv2

The problem here is that there going to be many such controls, one per each row of each child repeater. All will have slightly different generated IDs. So instead of querying them by id (impossible), you can use jQuery to quickly find them relatively to the txt that fired an event:

This answers the immediate question in this thread on how to get hold of the element. But I am not sure it will solve your bigger problem of enabling/disabling validation. You cannot easily do so with server side controls in javascript. Besides, validator is not disabled by default in your code. Although I believe all this is worth a separate question here on SO>

Note