Lets add to our project new web user control :
Right click on project->Add new item-> Web User Control
Lets call it DatePickerControl
copy the markup code inside the
<input name="DatePickerControl1$txtBirthDate" type="text" id="DatePickerControl1_txtBirthDate" name="txtBirthDate" style="height:24px;" />
One way to solve this problem is to register the javascript in the Load Page event of contol:
string script = "<script type=\"text/javascript\">$(function() {"+
"$('#"+txtBirthDate.ClientID + "').datepick({maxDate: 0});"+
"$('#form1').validate({" +
"errorPlacement: $.datepick.errorPlacement," +
"rules: {" +
"txtBirthDate: { dpMaxDate: [] }" +
"}," +
"messages: {" +
" txtBirthDate: '<span style=\"color:red\">The date is icorrent or later than now!</span>'" +
" } " +
"});" +
"});</script>";
Page.RegisterClientScriptBlock("datepickerfuncs",script);