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

Validate to prevent entering non existent date in Textbox inside Itemtemplate in a grid

2 Answers 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joselina
Top achievements
Rank 1
Joselina asked on 14 Nov 2013, 04:52 PM
Hi ,

I have to prevent entering a non existent date like (11/31/2013..etc) and also needs to consider leap year . I tried with java script function but couldn't achieve it. Can you please help me to get the validation function for the text box txtLaunchDate in java script?

Below is my Radgrid code...
<AN:ANGrid ID="grdEmails" runat="server" Width="100%" AutoGenerateColumns="false" ShowGroupPanel="false" ClientSettings-AllowDragToGroup="false">
 <MasterTableView DataKeyNames="ID">
    <Columns>
     <telerik:GridBoundColumn DataField="EmailTypeName" HeaderText="Email Type" SortExpression="EmailTypeName" />
    <telerik:GridBoundColumn DataField="RequestSubject" HeaderText="Subject" SortExpression="RequestSubject" />
        <telerik:GridTemplateColumn UniqueName="LaunchDate" HeaderText="Launch Date" SortExpression="Name">
        <ItemTemplate>
               <asp:TextBox ID="txtLaunchDate" runat="server" ToolTip="Enter email launch date in MM/DD/YYYY format here" CssClass="controls" Width="200" OnTextChanged="PreventNonexistentDate"></asp:TextBox>
   <AN:ANButton ID="btnStopDelinquentNotices" runat="server" Text="Stop Delinquent Notices" Visible="false" />
</ItemTemplate>
</telerik:GridTemplateColumn>
 <telerik:GridTemplateColumn UniqueName="LaunchDays" HeaderText="Number of Days before Contract Expiration" SortExpression="Name" Display="false">
    <ItemTemplate>
    <AN:ANNumericTextBox ID="txtDays" runat="server" Type="Number" Value="0" ></AN:ANNumericTextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
     </Columns>
   </MasterTableView>
   </AN:ANGrid>

Thanks
Joselina

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 15 Nov 2013, 06:04 AM
Hi Joselina,

You can add the CompareValidator to the TextBox you want to check the Date Format. Please try the following code snippet.

ASPX:
<telerik:GridTemplateColumn UniqueName="LaunchDate" HeaderText="Launch Date" SortExpression="Name">
    <ItemTemplate>
        <asp:TextBox ID="txtLaunchDate" runat="server" ToolTip="Enter Launch Date in MM/DD/YYYY format here"></asp:TextBox>
        <asp:CompareValidator ID="dateValidator" ControlToValidate="txtLaunchDate" Text="Incorrect Date"
            Operator="DataTypeCheck" Type="Date" runat="server" SetFocusOnError="true" />
    </ItemTemplate>
</telerik:GridTemplateColumn>

Thanks,
Princy
0
Joselina
Top achievements
Rank 1
answered on 15 Nov 2013, 04:00 PM
Thanks a lot Princy. Your code helped me lot.

Thanks
Joselina.
Tags
Grid
Asked by
Joselina
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Joselina
Top achievements
Rank 1
Share this question
or