Link to home
Start Free TrialLog in
Avatar of webressurs
webressursFlag for Norway

asked on

Validate textbox inside Ajax:TabContainer using ControlToValidate

I have some controls (textboxes) inside different Ajax:TabPanels that I need to validate. Since I validate controls in different panels I have to place the asp:RequiredFieldValidator below the TabContainer. Then the user will see all errormessages from different panels at the same time.

But, the asp:RequiredFieldValidator cant find the controls inside the tab container. How can I use asp:RequiredFieldValidator for controls inside a tab panel? Se attached code.
<asp:ScriptManager ID="ScriptManager" runat="server" />        
 
<Ajax:TabContainer ID="TabContainer" runat="server" ActiveTabIndex="0" EnableViewState="true" Width="98%">
    <Ajax:TabPanel runat="server" HeaderText="Generelt" ID="TabGeneral">
        <ContentTemplate> 
 
            <asp:TextBox runat="server" ID="txtUsername" />
            <asp:TextBox runat="server" ID="txtFirstname" />
            <asp:TextBox runat="server" ID="txtLastname" />
           
        </ContentTemplate>
    </Ajax:TabPanel>
    <Ajax:TabPanel runat="server" HeaderText="Plassering" ID="TabAdvanced">
        <ContentTemplate>
 
            //Other controls here
       
        </ContentTemplate>
    </Ajax:TabPanel>
    <Ajax:TabPanel runat="server" HeaderText="Interesser" ID="TabInterests">
        <ContentTemplate>
       
	    //Other controls here
     
        </ContentTemplate>
    </Ajax:TabPanel>
</Ajax:TabContainer>
 
<asp:RequiredFieldValidator runat="server" ID="reqUsername" Display="Dynamic" ErrorMessage=" -Missing Username" ControlToValidate="txtUsername" />
<asp:RequiredFieldValidator runat="server" ID="reqFirstname" Display="Dynamic" ErrorMessage=" -Missing Firstname" ControlToValidate="txtFirstname" />
<asp:RequiredFieldValidator runat="server" ID="reqLastname" Display="Dynamic" ErrorMessage=" -Missing Lastname" ControlToValidate="txtLastname" />
 
<asp:Button runat="server" ID="btnSaveUser" OnClick="btnSaveUser_Click" Text="Lagre" CausesValidation="true" />

Open in new window

Avatar of amar31282
amar31282
Flag of India image

I think you need to put the RequiredFieldValidator inside the Ajax Tab Panel
Avatar of webressurs

ASKER

Hi! I dont think the ValidatorCalloutExtender is solving this problem. It just add anoother way to display the errormessage, still inside the panel. I need to desplay the error message below (outside) the panel...
these links provide info about how to find the control inside ajax panel and you can implement validator accordingly
ASKER CERTIFIED SOLUTION
Avatar of prairiedog
prairiedog
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
check if it works
<asp:ScriptManager ID="ScriptManager" runat="server" />        
 
<Ajax:TabContainer ID="TabContainer" runat="server" ActiveTabIndex="0" EnableViewState="true" Width="98%">
    <Ajax:TabPanel runat="server" HeaderText="Generelt" ID="TabGeneral">
        <ContentTemplate> 
 
            <asp:TextBox runat="server" ID="txtUsername" />
            <asp:TextBox runat="server" ID="txtFirstname" />
            <asp:TextBox runat="server" ID="txtLastname" />
           
        </ContentTemplate>
    </Ajax:TabPanel>
    <Ajax:TabPanel runat="server" HeaderText="Plassering" ID="TabAdvanced">
        <ContentTemplate>
 
            //Other controls here
       
        </ContentTemplate>
    </Ajax:TabPanel>
    <Ajax:TabPanel runat="server" HeaderText="Interesser" ID="TabInterests">
        <ContentTemplate>
       
            //Other controls here
     <asp:Button runat="server" ID="btnSaveUser" OnClick="btnSaveUser_Click" Text="Lagre" CausesValidation="true" />
        </ContentTemplate>
    </Ajax:TabPanel>
</Ajax:TabContainer>
 
<asp:RequiredFieldValidator runat="server" ID="reqUsername" Display="Dynamic" ErrorMessage=" -Missing Username" ControlToValidate="txtUsername" />
<asp:RequiredFieldValidator runat="server" ID="reqFirstname" Display="Dynamic" ErrorMessage=" -Missing Firstname" ControlToValidate="txtFirstname" />
<asp:RequiredFieldValidator runat="server" ID="reqLastname" Display="Dynamic" ErrorMessage=" -Missing Lastname" ControlToValidate="txtLastname" />
 

Open in new window

OOPS i think i am late and did what @prairiedog just explained before me