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

Client-side Validation not working in grid, when link buttons in CommandItemTemplate are clicked

2 Answers 336 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael Hunt
Top achievements
Rank 1
Michael Hunt asked on 30 Nov 2011, 12:52 PM
Hi,

I am using version 2011.1.519.35 of your ASP.NET for AJAX controls.

My problem is that client-side validation isn't firing when I click a linkbutton in the CommandItemTemplate.

My grid has a CommandItemTemplate which contains linkbuttons to put the grid into add or edit mode, and a button to save rows that are in add or edit mode.  See below:

<CommandItemTemplate>
  <div class="gridCommandItemRow">
      <asp:LinkButton runat="server" ID="AddNew" Text="Add New" CssClass="add" 
            CommandName="InitInsert" 
            Visible="<%# Not TeamMetricsRadGrid.MasterTableView.IsItemInserted %>" />
     <asp:LinkButton runat="server" ID="UpdateAll" Text="Save All" CssClass="save" 
                  CommandName="SaveAll" 
                  CausesValidation="true" />
  </div>
</CommandItemTemplate>

I also have the following line in the grid, to try to get validation to work:

<ValidationSettings CommandsToValidate="SaveAll,PerformInsert,Update" 
          ValidationGroup="TeamMetricsValidationGroup" />

I have asp.net required field validator controls on several of the controls within EditItemTemplates.

Prior to using my own linkbuttons in the CommandItemTemplate, I was using the built-in Add / Edit buttons supplied by the GridEditCommandColumn.  When I did this, the client-side validation was firing correctly, and preventing the postback as expected.

 

But my linkbutton in the CommandItemTemplate, with the CommandName of "SaveAll" is NOT firing client-side validation.  It does a postback without validation.

 

I thought I could set CausesValidation="true" for that button, and add that button's CommandName to the CommandsToValidate property, as I've done above, but that didn't work.  Does the grid validation not work with CommandNames from other buttons, in the CommandToValidate property, like I've done?

 

What am I missing?  Is it possible to fire client-side validation from buttons in the CommandItemTemplate?

Thanks,
Michael

2 Answers, 1 is accepted

Sort by
0
Accepted
Andrey
Telerik team
answered on 05 Dec 2011, 12:34 PM
Hello Michael,

Th goal of these properties is to ease you when you are dealing with built-in command buttons. With CommandsToValidate property you could customize the built-in commands that are causing the validation.

For custom buttons you need to set explicitly the ValidationGroup property of the respective button in order to fire the validation. In your case you do not need to set these properties at all.

You code should be something similar to this:

<CommandItemTemplate>
               <div class="gridCommandItemRow">
                   <asp:LinkButton runat="server" ID="AddNew" Text="Add New" CssClass="add" CommandName="InitInsert"></asp:LinkButton>
                   <asp:LinkButton runat="server" ID="UpdateAll" Text="Save All" CssClass="save" CommandName="SaveAll" ValidationGroup="TeamMetricsValidationGroup"></asp:LinkButton>
               </div>
           </CommandItemTemplate>


Give these suggestion a try and check whether the problems is resolved.

Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Michael Hunt
Top achievements
Rank 1
answered on 05 Dec 2011, 04:00 PM
Thanks so much!  I was making it too complicated... thinking that something special had to be done.
Tags
Grid
Asked by
Michael Hunt
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Michael Hunt
Top achievements
Rank 1
Share this question
or