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

asp:RequiredFieldValidator enables postback of inline record even when validation fails.

2 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
L. M. Pathan
Top achievements
Rank 1
L. M. Pathan asked on 02 Dec 2011, 03:13 PM
Dear Telerik Team,

Though I have asp:RequiredFieldValidator to validate fields in inline edit form, when I click submit button validators doesn't stop postback when field value is empty.

I look forward to have your assistance. I can provide other page if required.

Regards

Pathan L.

<code>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<telerik:RadCodeBlock runat="server" ID="radCodeBlock">

    <script type="text/javascript">

        function onAddressRadToolBarButtonClicking(sender, args) {
            var masterTableViewAddress = getMaterTableViewAddress();
            if (masterTableViewAddress != null) {
                var comandNameAddress = args.get_item().get_commandName();
                if (comandNameAddress == 'Delete') {
                    if (masterTableViewAddress.get_selectedItems().length > 0) {
                        args.set_cancel(!confirm('Are you sure you want to delete selected address/s?'));
                    }
                    else {
                        alert('You must select a grid row first before processing delete.');
                        args.set_cancel(true);
                    }
                }
                else if (comandNameAddress == 'ToggleFilterBar') {
                if (masterTableViewAddress.get_isFilterItemVisible()) {
                        hideFilterItemAddress(masterTableViewAddress);
                    }
                    else {
                        showFilterItemAddress(masterTableViewAddress);
                    }
                    args.set_cancel(true);
                }
            }
        }


        function getMaterTableViewAddress() {
            var gridAddress = $find("<%=rdgAddressGrid.ClientID %>");
            return gridAddress.get_masterTableView();
        }


        function showFilterItemAddress(masterTableViewAddress) {
            masterTableViewAddress.showFilterItem();
        }
        
        function hideFilterItemAddress(masterTableViewAddress) {
            masterTableViewAddress.hideFilterItem();
        } 
    </script>


</telerik:RadCodeBlock>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanelAddress" runat="server" Skin="Vista">
</telerik:RadAjaxLoadingPanel>
<telerik:RadGrid ID="rdgAddressGrid" runat="server" Skin="Vista" AllowPaging="True"
    AllowSorting="True" AllowMultiRowSelection="true" AutoGenerateColumns="False"
    OnNeedDataSource="rdgAddressGrid_NeedDataSource" Width="99%" ShowStatusBar="True"
    GridLines="None" PageSize="5" AllowFilteringByColumn="true" OnItemCommand="rdgAddressGrid_ItemCommand"
    EnableViewState="true" OnItemDataBound="rdgAddressGrid_ItemDataBound" 
    OnPreRender="rdgAddressGrid_PreRender" onload="rdgAddressGrid_Load">
    <ValidationSettings EnableValidation="true" ValidationGroup="AddressGrid" CommandsToValidate="PerformInsert, Update" />
    <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" PrevPageToolTip="Previous"
        NextPagesToolTip="Next" />
    <MasterTableView EditMode="EditForms" Name="mtvPhone" CommandItemDisplay="Top" DataKeyNames="intAddressID, intStudentID">
    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
        <Columns>
            <telerik:GridClientSelectColumn UniqueName="CheckboxSelectColumn" ItemStyle-HorizontalAlign="Left">
                <HeaderStyle Width="25px" />
                <ItemStyle HorizontalAlign="Center" />
            </telerik:GridClientSelectColumn>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                <HeaderStyle Width="30px" />
                <ItemStyle HorizontalAlign="Center" />
            </telerik:GridEditCommandColumn>
            <telerik:GridCheckBoxColumn DataField="ysnPrimaryAddress" ConvertEmptyStringToNull="true"
                DefaultInsertValue="false" HeaderText="Primary" SortExpression="ysnPrimaryAddress"
                UniqueName="ysnPrimaryAddress" HeaderTooltip="Primary" AllowFiltering="false">
                <HeaderStyle Width="50px" />
                <ItemStyle HorizontalAlign="Center" />
            </telerik:GridCheckBoxColumn>
            <telerik:GridBoundColumn DataField="strAddressType" HeaderText="Address Type" SortExpression="strAddressType"
                UniqueName="strAddressType" HeaderTooltip="Address Type" CurrentFilterFunction="Contains">
                <HeaderStyle Width="90px" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="strAddress1" HeaderText="Address 1" SortExpression="strAddress1"
                UniqueName="strAddress1" HeaderTooltip="Address 1" CurrentFilterFunction="Contains">
                <HeaderStyle Width="125px" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="strAddress2" HeaderText="Address 2" SortExpression="strAddress2"
                UniqueName="strAddress2" HeaderTooltip="Address 2" CurrentFilterFunction="Contains">
                <HeaderStyle Width="125px" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="strStreet" HeaderText="Street" SortExpression="strStreet"
                UniqueName="strStreet" HeaderTooltip="Street" CurrentFilterFunction="Contains">
                <HeaderStyle Width="125px" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="strCity" HeaderText="City" SortExpression="strCity"
                UniqueName="strCity" HeaderTooltip="City" CurrentFilterFunction="Contains">
                <HeaderStyle Width="90px" />
            </telerik:GridBoundColumn>
        </Columns>


<PagerStyle AlwaysVisible="True"></PagerStyle>
        <CommandItemTemplate>
            <telerik:RadToolBar Skin="Vista" ID="rtbAddressCommand" OnClientButtonClicking="onAddressRadToolBarButtonClicking"
                runat="server" AutoPostBack="true">
                <Items>
                    <telerik:RadToolBarButton Text="Add new address" ID="btnInitInsertAddress" runat="server"
                        CommandName="InitInsert" ImageUrl="~/images/telerik/AddRecord.gif" ImagePosition="Left">
                    </telerik:RadToolBarButton>
                    <telerik:RadToolBarButton Text="Delete address" ID="btnDeleteAddress" runat="server"
                        CommandName="Delete" ImageUrl="~/images/telerik/Delete.gif" ImagePosition="Left">
                    </telerik:RadToolBarButton>
                    <telerik:RadToolBarButton Text="Toggle filtering" ID="ToggleFilteringAddress" runat="server"
                        CommandName="ToggleFilterBar" ImageUrl="~/images/telerik/search.png" ImagePosition="Left">
                    </telerik:RadToolBarButton>
                    <telerik:RadToolBarButton Text="Refresh" ID="btnRefreshAddress" runat="server" CommandName="RebindGrid"
                        ImageUrl="~/images/telerik/Refresh.gif" ImagePosition="Left" CausesValidation="false">
                    </telerik:RadToolBarButton>
                </Items>
            </telerik:RadToolBar>
        </CommandItemTemplate>
        <EditFormSettings ColumnNumber="3" EditFormType="Template" CaptionFormatString="Edit details for Address with ID {0}"
            CaptionDataField="intAddressID">
            <EditColumn ButtonType="ImageButton" InsertText="Insert" UpdateText="Update" UniqueName="EditCommandColumn1"
                CancelText="Cancel">
            </EditColumn>
            <FormTemplate>
                <table width="100%">
                    <tr>
                        <td style="vertical-align: top;">
                            <table border="0" width="80%">
                                <colgroup>
                                    <col width="50%" />
                                    <col width="50%" />
                                </colgroup>
                                <tbody>
                                    <tr>
                                        <td colspan="2" style="font-weight: bold">
                                            <%-- Edit details for Address with ID--%>
                                            <asp:Label ID="lblEditDetails" Text='<%# (Container is GridEditFormInsertItem) ? "" : "Edit details for Address with ID: "+ Eval( "intAddressID") %>'
                                                runat="server"></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="vertical-align: top;">
                                            <table border="0" cellspacing="5" cellpadding="5">
                                                <tbody>
                                                    <tr>
                                                        <td align="left">
                                                            <label>
                                                                Is Primary:</label>
                                                        </td>
                                                        <td align="left">
                                                            <asp:CheckBox ID="chkPrimary" Checked='<%#Bind("ysnPrimaryAddress")%>' runat="server" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left">
                                                            <label>
                                                                Address Type:</label>
                                                        </td>
                                                        <td>
                                                            <telerik:RadComboBox CssClass="TelerikTextBox2" Width="200px" AccessKey="T" ID="ddlAddressType"
                                                                runat="server" AppendDataBoundItems="True" Filter="Contains" 
                                                                CausesValidation="False" ValidationGroup="AddressGrid">
                                                            </telerik:RadComboBox>
                                                            <br />
                                                            <asp:RequiredFieldValidator ID="rfvAddressType" runat="server" ControlToValidate="ddlAddressType"
                                                                ErrorMessage="Address Type is missing." Display="Dynamic" ValidationGroup="AddressGrid" CssClass="validator">
                                                            </asp:RequiredFieldValidator>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left">
                                                            <label>
                                                                Address 1:
                                                            </label>
                                                        </td>
                                                        <td align="left">
                                                            <telerik:RadTextBox CssClass="TelerikTextBox2" ID="txtAddress1" Text='<%# Bind( "strAddress1") %>'
                                                                runat="server" Width="200px" MaxLength="50" ValidationGroup="AddressGrid">
                                                            </telerik:RadTextBox><br />
                                                            <asp:RequiredFieldValidator ID="rfvAddress1" runat="server" ControlToValidate="txtAddress1"
                                                                ErrorMessage="Address 1 is missing." Display="Dynamic" CssClass="validator" ValidationGroup="AddressGrid"></asp:RequiredFieldValidator>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left">
                                                            <label>
                                                                Address 2:</label>
                                                        </td>
                                                        <td align="left">
                                                            <telerik:RadTextBox ID="txtAddress2" CssClass="TelerikTextBox2" Text='<%# Bind( "strAddress2") %>'
                                                                runat="server" Width="200px" MaxLength="50">
                                                            </telerik:RadTextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left">
                                                            <label>
                                                                Street:</label>
                                                        </td>
                                                        <td align="left">
                                                            <telerik:RadTextBox ID="txtStreet" CssClass="TelerikTextBox2" Text='<%# Bind( "strStreet") %>'
                                                                runat="server" Width="200px" MaxLength="50">
                                                            </telerik:RadTextBox>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <td style="vertical-align: top;">
                                            <table border="0" cellspacing="5" cellpadding="5">
                                                <tbody>
                                                    <tr>
                                                        <td align="left">
                                                            <label>
                                                                City:</label>
                                                        </td>
                                                        <td align="left">
                                                            <telerik:RadTextBox CssClass="TelerikTextBox2" ID="txtCity" Text='<%# Bind( "strCity") %>'
                                                                runat="server" MaxLength="50" ValidationGroup="AddressGrid">
                                                            </telerik:RadTextBox><br />
                                                            <asp:RequiredFieldValidator ID="rfvCity" runat="server" ControlToValidate="txtCity"
                                                                ErrorMessage="City is missing." Display="Dynamic" CssClass="validator" ValidationGroup="AddressGrid"></asp:RequiredFieldValidator>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left">
                                                            <label>
                                                                Zip:</label>
                                                        </td>
                                                        <td align="left">
                                                            <telerik:RadTextBox CssClass="TelerikTextBox2" ID="txtZip" Text='<%# Bind("strZip") %>'
                                                                runat="server" MaxLength="50">
                                                            </telerik:RadTextBox><br />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left">
                                                            <label>
                                                                State:</label>
                                                        </td>
                                                        <td align="left">
                                                            <telerik:RadComboBox CssClass="TelerikTextBox2" Width="130px" Skin="Vista" ID="ddlState"
                                                                runat="server" MarkFirstMatch="true" Filter="Contains" AllowCustomText="false">
                                                                <Items>
                                                                    <telerik:RadComboBoxItem Value="Gujarat" Text="Gujarat" />
                                                                </Items>
                                                            </telerik:RadComboBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="left">
                                                            <label>
                                                                Country:</label>
                                                        </td>
                                                        <td align="left">
                                                            <telerik:RadComboBox CssClass="TelerikTextBox2" Width="130px" Skin="Vista" ID="ddlCountry"
                                                                runat="server" MarkFirstMatch="true" Filter="Contains" AllowCustomText="false">
                                                                <Items>
                                                                    <telerik:RadComboBoxItem Value="India" Text="India" />
                                                                </Items>
                                                            </telerik:RadComboBox>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" align="left">
                                            <asp:ImageButton ImageUrl="~/images/telerik/tick.gif" ID="btnUpdate" ValidationGroup="AddressGrid"
                                                CausesValidation="true" runat="server" CommandName='<%# (Container as GridItem).OwnerTableView.IsItemInserted ? "PerformInsert" : "Update" %>'>
                                            </asp:ImageButton>&nbsp;
                                            <asp:ImageButton ID="btnCancel" ImageUrl="~/images/telerik/cancel.gif" runat="server"
                                                CausesValidation="False" CommandName="Cancel"></asp:ImageButton>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                </table>
            </FormTemplate>
        </EditFormSettings>
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>


        <RowIndicatorColumn Visible="false">
        </RowIndicatorColumn>
    </MasterTableView>
    <ClientSettings AllowColumnsReorder="True" AllowKeyboardNavigation="true" AllowAutoScrollOnDragDrop="true"
        ReorderColumnsOnClient="true" AllowDragToGroup="True" EnableRowHoverStyle="true">
        <Selecting AllowRowSelect="True" />
        <Selecting AllowRowSelect="True" />
        <ClientMessages DragToGroupOrReorder="Select All" />
        <Scrolling AllowScroll="true" SaveScrollPosition="true" UseStaticHeaders="true">
        </Scrolling>
        <Resizing AllowColumnResize="true" EnableRealTimeResize="true" AllowRowResize="true" />
    </ClientSettings>
    <FilterMenu EnableEmbeddedSkins="true">
    </FilterMenu>
</telerik:RadGrid>
<asp:SqlDataSource ID="dsAddressType" runat="server" ConnectionString="<%$ ConnectionStrings:NirmalNiketalCNetWeb_ConnectionString %>"
    SelectCommand="usp_GetReferenceChildByParentName" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:Parameter Name="strParentName" Type="String" DefaultValue="AddressType" />
    </SelectParameters>
</asp:SqlDataSource>

<code/>

2 Answers, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 05 Dec 2011, 04:22 PM
Hello L. M. Pathan,

I have tried to reproduce the issue locally, but without success. Based on your code, I have built a sample project that works as expected on my side. Please review it and let me know whether I missed something out.

Regards,
Antonio Stoilkov
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
Vijay
Top achievements
Rank 1
answered on 11 Sep 2014, 09:08 AM
Add following line in web.config and check....

<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />

Tags
Grid
Asked by
L. M. Pathan
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Vijay
Top achievements
Rank 1
Share this question
or