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

RequiredFieldValidator on RadWindow

2 Answers 273 Views
Window
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Michael asked on 20 May 2011, 08:21 PM

As a new user of the Telerik controls I am still feeling my way around - I'm used to the Infragistcs control suite so I'm sure there is something simple I am missing.  Here is the problem:

1) Master Page with standar header/footer, content panel
2) Child Content Page with RadGrid, RadToolBar
3) RadToolBar has an "Add" button which does an async postback - the handler calls a method which configures the Title and IconUrl of the RadWindow (since it functions for both "add" and "edit") and then adds script function call to open the RadWindow - works fine - the RadWindow opens as expected.
4) There are two asp:TextBox controls on the RadWindow and both have RequiredFieldValidators configured
5) There are two buttons - "Cancel" and "Save" - the cancel button functions fine and prompt's user to confirm cancellation and closes the RadWindow if true otherwise does not. "CausesValidation" is set to false on the Cancel button.
6) The Save button has "CausesValidation" set to true - but when I click the button the validation does not appear to work because the page post's back and I get an error because I'm trying to save a record with no values.

The question is, why are the RequiredFieldValidators not "firing" - I expect the error text to show and focus to be set to the control failing validation - am I missing a setting or something??  Here is the content page markup...also attached an image of what the page looks like when the RadWindow is opened in "add" context.

 

<%@ Page Title="" Language="C#" MasterPageFile="~/ToolMaster.Master" AutoEventWireup="true" CodeBehind="Roles.aspx.cs" Inherits="SAIC.ISR.CMO.WebUI.Roles" %>
<%@ MasterType VirtualPath="~/ToolMaster.Master" %>
<asp:Content ID="RolesContent" ContentPlaceHolderID="MasterContentPlaceHolder" runat="server">
    <div class="pageContentOuter">
        <div class="pageContentInner">
            <br />
            <div class="group" style="width: 98%;">
                <div class="groupHeader">
                    <span class="left">
                        <span class="small-white-bold-label">Roles</span>
                    </span>
                    <span class="right">
                        <asp:Label ID="RecordCountLabel" runat="server" CssClass="small-white-bold-label">
                        </asp:Label>
                    </span>
                </div>
                <div class="groupToolbar">
                    <div class="groupToolbarContent">
                        <telerik:RadToolBar ID="RolesRadToolbar" runat="server" Width="100%" OnButtonClick="RolesRadToolbar_ButtonClick">
                            <Items>
                                <telerik:RadToolBarButton AccessKey="N" Text="New" CausesValidation="false" PostBack="true" ToolTip="Create New Role" 
                                    CommandName="New" ImageUrl="Content/Images/add16.png" ImagePosition="Left"></telerik:RadToolBarButton>
                                <telerik:RadToolBarButton AccessKey="R" Text="Refresh" CausesValidation="false" PostBack="true" ToolTip="Refresh Roles List" 
                                    CommandName="Refresh" ImageUrl="Content/Images/refresh16.png" ImagePosition="Left"></telerik:RadToolBarButton>
                            </Items>
                        </telerik:RadToolBar>
                    </div>
                </div>
                <div class="groupContent">
                    <telerik:RadGrid ID="RolesRadGrid" runat="server" AllowPaging="true"
                        AllowSorting="true"
                        AutoGenerateEditColumn="false"
                        AutoGenerateDeleteColumn="false"
                        PageSize="15"
                        ShowStatusBar="true"
                        OnItemDataBound="RolesRadGrid_ItemDataBound"
                        OnDeleteCommand="RolesRadGrid_DeleteCommand"
                        OnEditCommand="RolesRadGrid_EditCommand"
                        OnPageIndexChanged="RolesRadGrid_PageIndexChanged">
                        <PagerStyle Mode="NextPrevAndNumeric" Position="Bottom" />
                        <MasterTableView AutoGenerateColumns="false" DataKeyNames="RoleID">
                            <Columns>
                                <telerik:GridBoundColumn UniqueName="RoleID" DataField="RoleID" DataType="System.Int32" Visible="false">
                                    <ItemStyle HorizontalAlign="Left" />
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="FullName" DataField="FullName" DataType="System.String" MaxLength="100" HeaderText="Role Name">
                                    <ItemStyle HorizontalAlign="Left" Width="20%" />
                                </telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn UniqueName="Description" DataField="Description" DataType="System.String" MaxLength="10" HeaderText="Role Description">
                                    <ItemStyle HorizontalAlign="Left" Width="80%" />
                                </telerik:GridBoundColumn>
                                <telerik:GridButtonColumn UniqueName="EditColumn" CommandName="Edit" ButtonType="ImageButton" ImageUrl="Content/Images/editbutton.png">
                                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="22px" Height="20px" />
                                </telerik:GridButtonColumn
                                <telerik:GridButtonColumn UniqueName="DeleteColumn" CommandName="Delete" ConfirmDialogType="RadWindow" 
                                    ConfirmTitle="Delete Role" ConfirmText="Are you sure you want to delete this role?" 
                                    ButtonType="ImageButton" ImageUrl="Content/Images/deleteButton.png">
                                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="22px" Height="20px" />
                                </telerik:GridButtonColumn
                            </Columns>
                            <NoRecordsTemplate>
                                <div class="center">
                                    <br />
                                    <br />
                                    <span class="small-black-bold-label">No Roles Found</span>
                                    <br />
                                    <br />
                                </div>
                            </NoRecordsTemplate>
                        </MasterTableView>
                    </telerik:RadGrid>
                </div>
            </div>
        </div>
    </div>
    <telerik:RadWindowManager ID="RolesRadWindowManager" runat="server" EnableEmbeddedScripts="true" EnableViewState="true">
        <Windows>
    <telerik:RadWindow ID="AddEditWindow" runat="server" Height="250px" Width="500px" EnableEmbeddedScripts="true" 
        Animation="Fade" Modal="true" Behaviors="None" KeepInScreenBounds="true" EnableViewState="true">
        <ContentTemplate>
            <div class="row">
                <span class="label" style="width: 30%;">
                    <asp:RequiredFieldValidator ID="RoleNameValidator" runat="server" ControlToValidate="RoleNameTextBox" CssClass="small-red-bold-label" 
                        Text="*" SetFocusOnError="true">
                    </asp:RequiredFieldValidator>
                    <span class="small-red-label">Role Name:</span>
                 </span>
                <span class="field" style="width: 65%;">
                    <asp:TextBox ID="RoleNameTextBox" runat="server" CausesValidation="true" CssClass="textbox" MaxLength="50" Width="300px"></asp:TextBox>
                </span>
            </div>
            <div class="row" style="height: 55px;">
                <span class="label" style="width: 30%;">
                    <asp:RequiredFieldValidator ID="DescriptionValidator" runat="server" ControlToValidate="RoleDescriptionTextBox" CssClass="small-red-bold-label" 
                        Text="*" SetFocusOnError="true">
                    </asp:RequiredFieldValidator>
                    <span class="small-red-label">Description:</span>
               </span>
               <span class="field" style="width: 65%;">
                    <asp:TextBox ID="RoleDescriptionTextBox" runat="server" CausesValidation="true" CssClass="textbox" TextMode="MultiLine" Height="50px" Width="300px"></asp:TextBox>
                </span>
            </div>
            <div class="row"><span class="label"></span><span class="field"></span></div>
            <div class="row">
                <span class="label" style="width: 48%;">
                    <asp:Button ID="SaveButton" CausesValidation="true" runat="server" Text="Save" Width="100px" OnClick="SaveButton_Click" />
                </span>
                <span class="field" style="width: 48%;">
                    <asp:Button ID="CancelButton" CausesValidation="false" runat="server" Text="Cancel" Width="100px" />
                </span>
            </div>
        </ContentTemplate>
    </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
      
    <asp:HiddenField ID="AddEditContextHidden" runat="server" />
    <div class="spacer"> </div>
</asp:Content>

2 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 24 May 2011, 12:10 PM

Hi Michael,

I tried reproducing your scenario as best as I could based on the provided information. On my end the validation is fired correctly, though. You can find my test page attached and here is a video from my experiment: http://screencast.com/t/mo7rwhgk. Is your setup different than mine? Am I missing something? Can you reproduce this behavior on my page? If so, please modify it accordingly and send it back to me so I can debug it locally and pinpoint the cause.

Please note that I have added the save button, the textboxes and the required field validators to a separate validation group just in case. On my end it works correctly even without this setting, but I recommend using it, because the RadWindow is used with its ContentTemplate property and thus the controls inside are actually a part of the main page. This could cause issues with other buttons and other validators if they are present on the page.

Just for the sake of test please put this form with the validators outside of the RadWindow directly in the main page. If they still do not work as expected please review your app settings, the way you use the AJAX and the general behavior of the validator controls, as then the issue would be a general one and not related to the RadWindow.



Regards,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Michael
Top achievements
Rank 2
Iron
Iron
Iron
answered on 26 May 2011, 04:03 PM
Thanks for the response - I've actually figured out how to use the grid PopUp edit mode for both adding and editing and use the validation controls such that I no longer need to use an "external" RadWindow to do so and I think that route is much cleaner.  If I ever need to do what I was originally attempting I will use your example as the template to do so.   You can mark this thread as closed.
Tags
Window
Asked by
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Marin Bratanov
Telerik team
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or