This is a migrated thread and some comments may be shown as answers.

[Solved] RequiredFieldValidator inside CommandItemTemplate

2 Answers 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lia
Top achievements
Rank 1
Lia asked on 17 Sep 2009, 11:14 AM
Hello everybody. I'm dealing with the following problem. I have a radgrid inside which I want to have a commandItemTemplate. This has some controls: one of them is a radtextbox. I would like to add a requiredfield validator to the textbox.
When I had the CausesValidation='True' property to a button inside the commandItemTemplate I found out that the event does never get fired.
How can I solve this problem?

P.S. If I put the CausesValidation to False I don't have the problem anymore.

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 18 Sep 2009, 09:04 AM
Hello Lia,

If you want to validate the textbox only on clicking a particular button, then you can set the validation group property which specifies that the buttons with CausesValidation = true from the edit form belong to that group. Check out the sample code below:
aspx:
<CommandItemTemplate> 
     <telerik:RadTextBox ID="RadTextBox1" ValidationGroup="group1" runat="server"></telerik:RadTextBox> 
     <asp:CustomValidator ID="CustomValidator1" ValidationGroup="group1"  ControlToValidate="RadTextBox1" runat="server" ErrorMessage="Invalid Input" OnServerValidate="CustomValidator1_ServerValidate"
     </asp:CustomValidator> 
                 
     <asp:Button ID="Button1" CausesValidation="false" runat="server" Text="Button1" /> 
     <asp:Button ID="Button2" runat="server" CausesValidation="true" ValidationGroup="group1" Text="Button2" /> 
</CommandItemTemplate> 
If this does not help, consider pasting your relevant code here.

Thanks
Princy.
0
Lia
Top achievements
Rank 1
answered on 28 Sep 2009, 08:44 AM
Thnak you. It helped solve my problem.
Tags
Grid
Asked by
Lia
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Lia
Top achievements
Rank 1
Share this question
or