Login or Sign Up to become a member!
LessThanDot Site Logo

LessThanDot

A Technical Community for IT Professionals

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Highly Rated Users

Forum
No Posts Rated

Top 50
Given
Received

Links

Wiki
Blog

Forum Statistics

Users
Members:
1879
Members Online:
1
Guests Online:
48

Total Post History
Posts:
81448
Topics:
18714

7-Day Post History
New Posts:
0
New Topics:
0
Active Topics:
0

Our newest member
mwojcik

Other

FAQ
All times are UTC [ DST ]

Google Ads

Client Side validation in a Gridview control

Please wait...

Client Side validation in a Gridview control

Postby sunilbablani10 on Tue Nov 29, 2011 8:08 pm

Actually i am trying to access textbox in the gridview but it says "CS0103: The name 'TextBox2' does not exist in the current context"

Here is the code:

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="sunilbablani.WebForm1" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7.     <title></title>
  8. </head>
  9. <body>
  10.     <form id="form1" runat="server">
  11.     <div>
  12.     <script type="text/javascript" language="javascript">
  13.         function CalculateAge() {
  14.             var tb = document.getElementById('<%= TextBox2.ClientID %>');
  15.             if (tb.value != "") {
  16.                 var birthYear = new Date(tb.value);
  17.                 var curYear = new Date().getFullYear();
  18.  
  19.                 var ta = document.getElementById('<%= TextBox3.ClientID %>')
  20.                 ta.value = curYear - birthYear;
  21.             }
  22.         }
  23.      </script>
  24.                    
  25.         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
  26.             <ContentTemplate>
  27.                 <asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True"
  28.                     AutoGenerateEditButton="True" EnableSortingAndPagingCallbacks="True"
  29.                     DataSourceID="ObjectDataSource1" AutoGenerateColumns="False">
  30.                    
  31.                     <Columns>
  32.                     <asp:BoundField DataField="can_id" HeaderText="CandidateID" ReadOnly="True" SortExpression="can_id" />
  33.                     <asp:TemplateField HeaderText="Name">
  34.                         <EditItemTemplate>
  35.                         <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("can_name") %>'></asp:TextBox>
  36.                         <asp:RequiredFieldValidator
  37.                           ID="RequiredFieldValidator1"
  38.                           Runat="server"
  39.                        ErrorMessage=""
  40.                             ControlToValidate="TextBox1">
  41.                             *</asp:RequiredFieldValidator>
  42.                         </EditItemTemplate>
  43.                     </asp:TemplateField>
  44.                    
  45.                     <asp:TemplateField HeaderText="DOB">
  46.                    
  47.                         <EditItemTemplate>
  48.                         <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("can_dob") %>'></asp:TextBox>
  49.                         <asp:RequiredFieldValidator
  50.                           ID="RequiredFieldValidator2"
  51.                           Runat="server"
  52.                        ErrorMessage=""
  53.                             ControlToValidate="TextBox2">
  54.                             *</asp:RequiredFieldValidator>
  55.                             <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox2"
  56.         ErrorMessage="DOB should be in MM/DD/YYYY format" Operator="DataTypeCheck" Type="Date">*</asp:CompareValidator>
  57.                         </EditItemTemplate>
  58.                     </asp:TemplateField>
  59.                     <asp:TemplateField HeaderText="Age">
  60.                         <EditItemTemplate>
  61.                         <asp:TextBox ID="TextBox3" runat="server" ReadOnly="true" Text='<%# Bind("can_age") %>'></asp:TextBox>
  62.                         </EditItemTemplate>
  63.                     </asp:TemplateField>
  64.                    
  65. </Columns>
  66.                 </asp:GridView>
  67.                 <asp:ValidationSummary ID="ValidationSummary1" Runat="server" />
  68.                 <asp:DetailsView ID="DetailsView1" runat="server"
  69.                     AutoGenerateInsertButton="True" DefaultMode="Insert" Height="50px"
  70.                     Width="125px" DataSourceID="ObjectDataSource1">
  71.                    
  72.                 </asp:DetailsView>
  73.                 <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
  74.                     SelectMethod="Select" TypeName="sunilbablani.Candidate">
  75.                 </asp:ObjectDataSource>
  76.                 <asp:ScriptManager ID="ScriptManager1" runat="server">
  77.                 </asp:ScriptManager>
  78.             </ContentTemplate>
  79.         </asp:UpdatePanel>
  80.    
  81.     </div>
  82.     </form>
  83. </body>
  84. </html>
  85.  


please help.
sunilbablani10
Apprentice
Apprentice
 
Posts: 42
Joined: Mon Apr 27, 2009 10:44 am
Unrated