webressurs
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.
But, the asp:RequiredFieldValidator
<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" />
I think you need to put the RequiredFieldValidator inside the Ajax Tab Panel
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...
i think then you need to use javascript
have a look on these links
http://forums.asp.net/p/1223866/2201455.aspx#2201455
http://www.developersdex.com/asp/message.asp?p=1116&r=6587759
http://www.velocityreviews.com/forums/t674159-how-to-find-control-with-javascript.html
https://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q__24245344.html
have a look on these links
http://forums.asp.net/p/1223866/2201455.aspx#2201455
http://www.developersdex.com/asp/message.asp?p=1116&r=6587759
http://www.velocityreviews.com/forums/t674159-how-to-find-control-with-javascript.html
https://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q__24245344.html
these links provide info about how to find the control inside ajax panel and you can implement validator accordingly
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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" />
OOPS i think i am late and did what @prairiedog just explained before me