Sajid Khan

Sajid Khan

  • NA
  • 56
  • 11.3k

how to validate calendar extender in gridview using jscript?

Dec 7 2016 3:55 AM
I have validated it to compare that date should less then today's date , now i need to validate it for one more requirement.  How to validate a calendar extender for (Close)date(must be greater then Start Date coming from database) in a gridview using jscript?  
 
here's the code :
 
<script language="javascript" type="text/javascript">
function CheckForBackDate(sender, args) {
var selectedDate = new Date();
selectedDate = sender._selectedDate;
var todayDate = new Date();
if (selectedDate.getDateOnly() > todayDate.getDateOnly()) {
sender._selectedDate = todayDate;
sender._textbox.set_Value(sender._selectedDate.format(sender._format));
alert("Closure date must be less then today's date");
}}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true"
EnableScriptLocalization="true" />
<asp:hyperlink id="HyperLink1" style="Z-INDEX: 106; LEFT: 648px; POSITION: absolute; TOP: 112px"
runat="server" ImageUrl="home.gif" NavigateUrl="menu.aspx">HyperLink</asp:hyperlink>
<table style="height: 500px; width: 450px" >
<tr>
<td class="style5">
<asp:Image ID="Image1" Style="z-index: 101; left: 0px; position: absolute; top: 0px;
width: 750px;" runat="server" Height="96px" ImageUrl="images/head2.gif"></asp:Image>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" Style="z-index: 102; left: 304px; position: absolute; top: 104px"
runat="server" Font-Underline="True" ForeColor="Maroon" Font-Bold="True"> Closure of Districts</asp:Label>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="gvDist" runat="server" AutoGenerateColumns="False" DataKeyNames="dist_cd"
Height="148px" Width="480px" Font-Size="Small" BorderWidth="1px"
OnItemCommand="itemrow" CellPadding="3" BorderColor="#CCCCCC" BackColor="White"
BorderStyle="None">
<Columns>
<asp:TemplateField HeaderText="S.no.">
<ItemTemplate>
<asp:Label ID="lblRowNumber" Text='<%# Container.DataItemIndex + 1 %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="dist_name_e" HeaderText="District" ItemStyle-Width="120px" >
<ItemStyle Width="120px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="start_date" HeaderText="Start Date" ItemStyle-Width="120px"
ApplyFormatInEditMode="true" SortExpression="SNAPSHOT_DATA_DATE" DataFormatString="{0:d}" >
<ItemStyle Width="120px"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Close Date (M-DD-YY)">
<ItemTemplate >
<asp:Label ID="txtDistCd" runat="server" Text='<%#Eval("dist_cd") %>' Visible="False" />
<asp:TextBox ID="txtCloseDate" runat="server" Width="80px" Text='<%#Eval("close_date", "{0:MM-dd-yyyy}")%>'></asp:TextBox>
<%--Onclick=" return checkMyDate_SM1();"--%>
<cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtCloseDate"
OnClientDateSelectionChanged ="CheckForBackDate"
OnClientShown="ChangeCalendarView" PopupButtonID="imgStartDate" Format="dd-MM-yyyy" >
</cc1:CalendarExtender>
<asp:ImageButton ID="imgStartDate" runat="server" ImageUrl="~/images/calender.jpg"
Width="20px" />
<%-- <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txtCloseDate"
Display="Dynamic" ErrorMessage="Invalid Date" Operator="DataTypeCheck" Type="Date">
</asp:CompareValidator>--%>
<%--<cc1:ValidatorCalloutExtender ID="CompareValidator1_ValidatorCalloutExtender" runat="server"
Enabled="True" TargetControlID="CompareValidator1">
</cc1:ValidatorCalloutExtender>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Click here">
<ItemTemplate>
<asp:Button ID="btnEdit" runat="server" Text="Save" CommandName="Update" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>

Answers (1)