Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

How to validate a user control in ASPX page

0.00/5 (No votes)
13 Jun 2011CPOL 14.5K  
How to validate a user control in ASPX page
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.

XML
<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.

C#
var a=document.getElementById('form1').elements("txt$txt");
    if(a.value=='')
    {
        alert("please enter value");
        return false;
    }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)