User control in asp.net + java script + validation





I created a user control for Countries using Microsoft Visual sutdio. I populated a dropdownlist ( Server Side ) using database and then I called this countrol in one of my web form. I wanted to validate this User control but it was not validating when I used “MyControl1.ClientID”  instead of this when i Use Asp.Net generated ID it worked. Can any one tell me why It happend.?<script type=”text/javascript”>

function textlen(source,arguments){var textlen=document.getElementById(“<%=TextBox1.ClientID%>”).value; var country=document.getElementById(‘ctl00_ContentPlaceHolder1_Country1_DropDownListCountries’).value; if (country==“Select a value” && textlen.length==0){arguments.IsValid=

false; return;}}</script>

This is my user control id  “ctl00_ContentPlaceHolder1_Country1_DropDownListCountries” Javascript was unable to get User control Id by using the following line

var country=document.getElementById(Country1.ClientID).value;

 Does any one  know why?







Tags: , , , , ,

Comments are closed.