Hi
I think it will be better to pass the id of both control to your method and then get the values from that and continue with your validation code.
for example....
modify the js method as...
function CompareDates(ctrlStartID, ctrlEndID)
{
var str1 = document.getElementByID(ctrlStartID);
var str2 = document.getElementByID(ctrlEndID);
}
and instead of assigning the onchange attribute on html, use the "rowdatabound" event of grid view and the both the control there and assign the onchange attribute and pass the client id of both the controls there.
like....
protected void yourgrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txtStart = (TextBox)e.Row.FindControl("txtStartDate");
TextBox txtEnd = (TextBox)e.Row.FindControl("txtEndDate");
txtStart.Attribute["onchange"] = "CompareDates('"+ txtStart.ClientID +"','"+ txtEnd.ClientID +"')";
txtEnd.Attribute["onchange"] = "CompareDates('"+ txtStart.ClientID +"','"+ txtEnd.ClientID +"')";
}
}
I will also prefer to use "onblur" event instead of "onchange"
Hope this will help you.