locked
Accessing TextBox vaue in Gridview EditItemTemplate in Javascript RRS feed

  • Question

  • User-173333858 posted

    Hello,

    I am trying to read a Date TextBox value in Javascript, but am unable to access it. Am attaching part of my code here.

    asp:GridView ID="GridVacCov" runat="server" BackColor="white" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" 
                           CellSpacing="2" HorizontalAlign="Center" ShowHeaderWhenEmpty="True" EmptyDataText="No data found for given Criteria!" 
                           AutoGenerateColumns="False" Width="100%" 
                           OnRowEditing="GridVacCov_RowEditing" 
                           OnRowCancelingEdit="GridVacCov_OnRowCancelingEdit"
                           OnRowUpdating="GridVacCov_OnRowUpdating"
                           OnRowCreated="GridVacCov_OnRowCreated"                                              
                           ShowFooter="true" FooterStyle-BackColor="White" 
                           FooterStyle-BorderColor="Black"  OnRowDeleting="GridVacCov_OnRowDeleting" OnRowDataBound="GridVacCov_OnRowDataBound">  
                            <FooterStyle BackColor="lightgray" ForeColor="#8C4510"  />  
                            <HeaderStyle BackColor="#133c70" Font-Bold="True" ForeColor="white" HorizontalAlign="Center"/>  
                            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />  
                            <RowStyle BackColor="white" ForeColor="black" HorizontalAlign="Center"/>  
                            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />  
                            <SortedAscendingCellStyle BackColor="#FFF1D4" />  
                            <SortedAscendingHeaderStyle BackColor="#B95C30" />  
                            <SortedDescendingCellStyle BackColor="#F1E5CE" />  
                            <SortedDescendingHeaderStyle BackColor="#93451F" /> 
                           
                           <emptydatarowstyle backcolor="white" forecolor="black"/>      
                            <emptydatatemplate>
                                <tr>                            
                                <td><asp:TextBox class="InsRec" width="95%" ID="BUBox" runat="server" ReadOnly="True" style="text-align:center" BackColor="LightGray"/></td>
                                <td><asp:TextBox class="InsRec" width="65%" ID="AreaBox" runat="server" style="text-align:center"/></td>
                                <td><asp:TextBox  class="InsRec" width="65%" ID="RegionBox" runat="server" style="text-align:center"/></td>
                                <td><asp:TextBox class="InsRec" width="65%" ID="DistrictBox" runat="server" style="text-align:center"/></td>
                                <td><asp:TextBox class="InsRec" width="85%" ID="StrNbrBox" runat="server" /></td>
                                
                                 <td> <asp:DropDownList ID="RiskRoleDropBox" runat="server" AutoPostBack="true" 
                                                  OnSelectedIndexChanged="RiskRoleDropBox_TextChanged" style="width:200px; background-color:lightgray">                                              
                                              </asp:DropDownList> </td>
    
    
                                <td><asp:TextBox class="InsRec" width="95%" ID="StartDtBox" runat="server" style="text-align:center"/></td> 
                                <td><asp:TextBox class="InsRec" width="95%" ID="EndDtBox" runat="server" style="text-align:center"/></td>
                                <td><asp:TextBox class="InsRec" width="95%" ID="StatusBox" runat="server" ReadOnly="True" BackColor="LightGray"/></td> 
                                <td><asp:TextBox class="InsRec" width="95%" ID="LastModDtTimeBox" runat="server" ReadOnly="True" BackColor="LightGray"/></td> 
                                <td><asp:TextBox class="InsRec" width="95%" ID="TktBox" runat="server" /></td>
                                <td><asp:TextBox class="InsRec" width="95%" ID="CmntsBox" runat="server" /></td> 
                                <td><asp:Button ID="EmptyGridAdd" class="InsRec" text="ADD Record" runat="server" onclick="GridVacCov_Insert"/></div></td>
                                    </tr>
                            </emptydatatemplate> 
                           <EmptyDataRowStyle HorizontalAlign="Center" />
    
                           <Columns>
                    <%--<asp:HyperLinkField HeaderText="Action" ItemStyle-Width="2%" NavigateUrl="#myModal"/>--%>
                               <asp:TemplateField HeaderText="Empl ID" ItemStyle-Width="8%" Visible="false">
                                   <controlstyle Width="65px"></controlstyle>
    
                                   <EditItemTemplate>
                                       <asp:TextBox ID="TextBox25" max-width="8%" runat="server" Text='<%# Bind("EMPLID") %>' ReadOnly="True"></asp:TextBox>
                                   </EditItemTemplate>
                                   <ItemTemplate>
                                       <asp:Label ID="Label23" runat="server" Text='<%# Bind("EMPLID") %>'></asp:Label>
                                   </ItemTemplate>
                                   <ItemStyle CssClass="EMPLID" Width="8%" />
                     <FooterTemplate>  
                                       <asp:TextBox width="95%" class="InsRec" ID="EmplIDTextBox" runat="server" />                                
                   </FooterTemplate>
                               </asp:TemplateField>
    
                                                     
    
                                <asp:TemplateField HeaderText="START DATE" ItemStyle-Width="7%">
                                    <controlstyle Width="90%"></controlstyle>
                                   <EditItemTemplate>
                                       <asp:TextBox ID="TextBox32" min-width="7%" runat="server" Text='<%# Bind("START_DATE", "{0:MM/dd/yyyy}") %>' ></asp:TextBox>
                                   </EditItemTemplate>
                                   <ItemTemplate>
                                       <asp:Label ID="Label30" runat="server" Text='<%# Bind("START_DATE", "{0:MM/dd/yyyy}") %>'></asp:Label>
                                   </ItemTemplate>
                                   <ItemStyle CssClass="START_DATE" Width="7%" />
                                    <FooterTemplate>  
                                       <asp:TextBox class="InsRec" width="95%" ID="StartDtTextBox" runat="server" style="text-align:center"/>           
                   </FooterTemplate>
                               </asp:TemplateField>
    
                                <asp:TemplateField HeaderText="END DATE" ItemStyle-Width="7%">
                                    <controlstyle Width="90%"></controlstyle>
                                   <EditItemTemplate>
                                       <asp:TextBox ID="TextBox33" min-width="7%" runat="server" Text='<%# Bind("END_DATE", "{0:MM/dd/yyyy}") %>' OnTextChanged="TextBox33_OnTextChanged"></asp:TextBox>                                   
                                   </EditItemTemplate>
                                   <ItemTemplate>
                                       <asp:Label ID="LabeL31" runat="server" Text='<%# Bind("END_DATE", "{0:MM/dd/yyyy}") %>'></asp:Label>
                                   </ItemTemplate>
                                   <ItemStyle CssClass="END_DATE" Width="7%" />
    
                                    <FooterTemplate>  
                                       <asp:TextBox class="InsRec" width="95%" ID="EndDtTextBox" runat="server" AutoPostBack="true"/>           
                   </FooterTemplate>
                               </asp:TemplateField>
    <asp:TemplateField HeaderText="ACTION" ItemStyle-Width="10%">
                           <controlstyle Width="48%"></controlstyle>
                          <ItemTemplate>                         
                                 <asp:Button ID="BtnEdit" runat="server" text="EDIT" CommandName="Edit" width="70px" BackColor="LightGray"></asp:Button>                            
                              <asp:Button ID="BtnDelete" runat="server" text="DELETE" CommandName="Delete" width="70px" BackColor="LightGray" ></asp:Button>
                                 <asp:Panel ID="Panel1" runat="server" BackColor="White" Height="250px" Width="458px" BorderColor="Black" BorderStyle="Solid">
                                     <div class="text-center">
                                         &nbsp;&nbsp;<br /> Are you sure you want to delete this record?<br /> <br />
                                         <br />
                                         <asp:Button ID="BtnYES" runat="server" Text="Yes" Width="89px" />
                                         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                         <asp:Button ID="BtnNO" runat="server" Text="No" Width="93px" />
                                     </div>
                                 </asp:Panel>
                              <ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="BtnDelete" DisplayModalPopupID="ConfirmDelMsgBox"/>
                              <ajaxToolkit:ModalPopupExtender ID="ConfirmDelMsgBox" runat="server" TargetControlID="BtnDelete" PopupControlID="Panel1" OkControlID="BtnYES" CancelControlID="BtnNO"></ajaxToolkit:ModalPopupExtender>
                                 
                          </ItemTemplate>
                          <EditItemTemplate>
                               <asp:Button ID="BtnUpdate" runat="server" text="UPDATE" CommandName="Update" width="70px" OnClientClick="ValidateDate()" ></asp:Button>
                              <asp:Button ID="BtnCancel" runat="server" Text="CANCEL" CommandName="Cancel" Width="70px"/>
                          </EditItemTemplate>
                                               
                           <ItemStyle CssClass="DelRec" />
    
                     <FooterTemplate>               
                        <div style="text-align:center"><asp:Button ID="Button2" class="InsRec" text="ADD Record" runat="server" onclick="GridVacCov_Insert"/></div>
                      </FooterTemplate>
                    </asp:TemplateField> 
    
    
    
    
    <script type="text/javascript">
    function ValidateDate() {
                alert("ALL OK!");
    
                var StartDt = document.getElementById("TextBox32").value;
                var EndDt = document.getElementById("TextBox33").value;
    
                alert(StartDt);
    
                EndDt = new Date(EndDt);
                StartDt = new Date(StartDt);
    
                if (EndDt < StartDt)
                    alert("Start Date should be less than the End Date.")
                else
                    alert("WHAT NOW?");
    
                return;
            }
    </script>

    I understand that since the Textboxes are inside the Gridview, the approach might be different. I tried accessing them thru the Gridview (GridVacCov) but that did not work too.

    Please let me know if anyone knows how to go about this.

    Thanks,

    -Rashmi

    Friday, June 7, 2019 7:15 PM

Answers

All replies