It's often needed to validate a user control in aspx page but
document.getElementById('controlname')
does not get us that usercontrol.
Suppose we create a user control that has only asp:text box named '
txt
', and we have to validate it in our page.
<myText:Textbox ID="txt" runat="server" Visible="true" />
<asp:Button ID="btnSumbit" runat="server" Text="Validate user control" OnClientClick="javascritp:return IsFilled()" />
You can use the following JavaScript to get that control.
var a=document.getElementById('form1').elements("txt$txt");
if(a.value=='')
{
alert("please enter value");
return false;
}