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

Prevent radbutton click until grid is validated

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 01 May 2020, 02:46 AM

I would like to tie the validation trigger to a radbutton that is external to a radgrid.

Example:

<telerik:RadButton ID="btnAddStatusComplete" runat="server" Text="Complete" OnClick="btnAddStatusComplete_Click">
</telerik:RadButton>

<telerik:RadGrid ID="rgAddStatusJustify" runat="server" AutoGenerateColumns="false" AllowPaging="false" AllowFilteringByColumn="false"
                 OnBatchEditCommand="rgAddStatusJustify_BatchEditCommand"
                 OnDeleteCommand="rgAddStatusJustify_DeleteCommand" OnNeedDataSource="rgAddStatusJustify_NeedDataSource" OnItemDataBound="rgAddStatusJustify_ItemDataBound">
    <MasterTableView Width="100%" AutoGenerateColumns="false" DataKeyNames="itemName" EditMode="Batch">
      <BatchEditingSettings EditType="Cell" HighlightDeletedRows="true"/>
      <Columns>
        <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" />
        <telerik:GridBoundColumn DataField="itemDescription" HeaderText="Item Description" ReadOnly="True" SortExpression="itemDescription" ItemStyle-HorizontalAlign="Left">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="userComment" HeaderText="Justification" UniqueName="userComment">
            <ItemStyle BorderStyle="Solid" Width="200" />
            <ColumnValidationSettings EnableRequiredFieldValidation="true">
                <RequiredFieldValidator ForeColor="Red" Text="*Comment is required" Display="Dynamic"></RequiredFieldValidator>
            </ColumnValidationSettings>
        </telerik:GridBoundColumn>
      </Columns>
    </MasterTableView>
</telerik:RadGrid>

I want the userComment field filled in for all rows prior to a postback being triggered by btnAddStatusComplete_Click.  Preferably the validation text will show up once they click "Complete" but am open to other/better approaches.

Thank you

1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 05 May 2020, 05:58 PM

Hello Dan,

Validating the Grid can be done in two different ways. Validating it on the Client or on the Server.

If you choose to validate on the server, a PostBack has to happen before you can manipulate the external button.

If you choose to validate on the Client, you can then use the CustomValidator's client event handler. When it fires, within the event handler you'll have the logic that validates the input, and if validation passes you change the external button.

<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator" ClientValidationFunction="MyValidatorFunction">
</asp:CustomValidator>

<script>
    function MyValidatorFunction(source, IsValid) {
        if (IsValid) {
            // find and enable the external button
        } else {
            // find and disable the external button
        }
    }
</script> 
See CustomValidator in ASP.NET and  CustomValidator.ClientValidationFunction Property for more information about the CustomValidator.

 

If you could describe more detailed the steps you want the Grid to do, I'll be able to give you better advice.

Kind regards,
Doncho
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Dan
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Share this question
or