Click here to Skip to main content
15,925,255 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a grid view in which i have fields and now i want when the field is in edititemtemplate or insertitemtemplate then it will validate using jquery . I tried but its not finding the control .

XML
 <% if (AdminDetail.CurrentMode == DetailsViewMode.Edit)
        {%>

     <script type="text/javascript">
        $().ready(function() {
            // validate signup form on keyup and submit
            $("#aspnetForm").validate({
                rules:
                {
                    <%=EditCompanyName.UniqueID %>: "required"

                },
                messages:
                {
                    <%=EditCompanyName.UniqueId %> : "required"

                }
            });
        });
    </script>
<%} %>




 <% if (AdminDetail.CurrentMode == DetailsViewMode.Edit)
          {  %>
<asp:DetailsView ID="AdminDetail" runat="server" Height="10px" Width="750px" DataKeyNames="adminuserid"
            OnItemCommand="AdminDetail_ItemCommand" OnModeChanging="AdminDetail_ModeChanging"
            AutoGenerateEditButton="True" AutoGenerateInsertButton="True" OnPageIndexChanging="AdminDetail_PageIndexChanging"
            AutoGenerateRows="False" AllowPaging="True" OnItemUpdating="AdminDetail_ItemUpdating"
            OnDataBound="AdminDetail_DataBound" OnItemInserting="AdminDetail_ItemInserting"
            CellPadding="4" ForeColor="#333333" GridLines="None">
            <FooterStyle BackColor="#EFEFEF" HorizontalAlign="Center" VerticalAlign="Middle"
                Height="60" />
            <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <Fields>
<asp:TemplateField HeaderText="Company Name" >
                <ItemTemplate>
                <asp:Label ID="LblPhone" runat="server" Text='<%#Bind("companyname") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate><asp:TextBox ID="EditCompanyName" runat="server" Text='<%#Bind("companyname") %>'></asp:TextBox></EditItemTemplate>
                </asp:TemplateField>
</asp:DetailsView>
        <%} %>


Its my code please reply
Posted
Updated 27-Sep-11 20:23pm
v2

I recommend you to open the page in a browser and select the view source option , and please verify the "id" for the controls you are trying to implement the validator.

I guess it will be different,Use that id you see in page source ,in the jquery for validator to work.
 
Share this answer
 
v2
Comments
Vimalrashamra 28-Sep-11 2:51am    
I tried it sir but still its giving same error that ctl00_PageContent_AdminDetail_EditCompanyName Does not exist in current context . And in the code i pasted i used the UniqueId which used the EditCompanyId as the id so i dont think its a problem .
XML
$("#aspnetForm").validate({
                rules: {
                    <%=EditCompanyName.UniqueID %>: {
                       
                        required: true
                    }


Please see view source of the page to know the name of the control "EditCompanyName" as it will be different, as its a part of gridview

Refer this
http://www.dotnetspark.com/kb/1532-gridview-and-jquery-asp-net-tutorial.aspx[^]
 
Share this answer
 
v2
Comments
Vimalrashamra 28-Sep-11 4:31am    
That's why i used the UniqueID

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900