65.9K
CodeProject is changing. Read more.
Home

How to validate a user control in ASPX page

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Jun 13, 2011

CPOL
viewsIcon

14619

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.
<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;
    }