Skip to content Skip to sidebar Skip to footer

Accessing Asp.net Controls In Javascript

I have following Javascript line in my ASP.NET web app: document.getElementById('<%=myTextBox[0].ClientID %>').value = 'test'; how can I access myTextBox elements? for insta

Solution 1:

Send this control id of textbox instead of sending index as asp.net control id might not be as you expect,

In Code behind

ddl.Attributes.Add("onChange", "return OnFoodChange(this,'" + myTextBox[i].ClientID + "');");

In HTML

functionOnFoodChange(myCmb,myTextBoxId) {
 currentTextBox = document.getElementById(myTextBoxId);
//Your code...
}

Solution 2:

You are trying to Mix Server side with Client side. it does not work like this. you need to transfer your server array to javascript on server then you will be able access its index on clien side.

Post a Comment for "Accessing Asp.net Controls In Javascript"