Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a generic user control for calenders using ajax toolkit.
i am using the user control in a gridview twice for two date fields ("Start Date" and "End Date")
How do i compare the two dates???

I tried it using the compare validator but it doesnt get the textbox id which is inside the usercontrol.

Would appreciate some ideas..

Thanks

This is my user control
C#
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AjaxDatePicker.ascx.cs" Inherits="TCS.AjaxDatePicker" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
<asp:TextBox ID="txtDatePicker" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="calExtndDatePicker" TargetControlID="txtDatePicker"  
    runat="server">
</asp:CalendarExtender>
Posted
Comments
Richard C Bishop 13-Aug-13 12:59pm    
Try accessing the parent of the controls first and see if you can find the ID inside that.
sourav kr agarwal 13-Aug-13 13:06pm    
yeah..but thats my problem..I just want that functionality in the gridview edit mode..so where do i write the code for getting the parent control...since the user control is inside the gridview
silvercr0w 13-Aug-13 13:31pm    
What is the code you used with the compare validator? Maybe it isn't finding the textbox id because it is being auto-generated in the gridview. Try adding clientidmode="static" in your control.

1 solution

this is compare validator inside gridview
C#
<asp:comparevalidator id="CompareValidator1" runat="server" errormessage="CompareValidator" xmlns:asp="#unknown"></asp:comparevalidator>
            <asp:ajaxdatepicker id="UControl2" title="Date Picker" runat="server" xmlns:asp="#unknown"></asp:ajaxdatepicker>


and this is my code behind for setting the control to validate property

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               AjaxDatePicker ajx = (AjaxDatePicker)e.Row.FindControl("UControl1");
               TextBox txtDatepicker = (TextBox)ajx.FindControl("txtDatePicker");
              // string id = txtDatepicker.UniqueID;
               AjaxDatePicker ajx1 = (AjaxDatePicker)e.Row.FindControl("UControl2");
               TextBox txtDatepicker1 = (TextBox)ajx.FindControl("txtDatePicker");
               //string id = txtDatepicker1.UniqueID;

               CompareValidator cmp = (CompareValidator)e.Row.FindControl("CompareValidator1");
               cmp.ControlToValidate = txtDatepicker1.UniqueID;
             //  string id=
           }
       }


I am getting the following error on running the page

Unable to find control id 'ctl00$ContentPlaceHolder1$GridView1$ctl02$UControl1$txtDatePicker' referenced by the 'ControlToValidate' property of 'CompareValidator1'.
 
Share this answer
 

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