Click here to Skip to main content
15,897,518 members
Articles / Web Development / ASP.NET
Tip/Trick

How to validate a user control in ASPX page

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
13 Jun 2011CPOL 14.4K   1  
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)


Written By
Software Developer (Senior) Siemens IT Solutions and Services Pvt. Ltd.
India India
I am a .NET Developer.

Comments and Discussions

 
-- There are no messages in this forum --