SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having a datetime control in sharepoint custom webpart


I want to call a js as well as server side function on date changed. I have done as above but, client side function does not execute. Can anyone help me in order to get this working wherein if a date is changed than both js on client side and onchange server side event should work.

In my case only server side is getting fired.

Thank you in advance.

share|improve this question
up vote 0 down vote accepted

Ok i got the solution to this.

I removed AutoPostBack="true" and in javascript i used __doPostBack('<%= txtUKdtofAdm.Controls[0].ClientID %>', ''); which forces a postback which inturn fires OnDateChanged="txtUKdtofAdm_OnDateChanged"

Thank You

share|improve this answer

I think you should remove the ; from the end of validateControlsUK(); and it will work. So your call should be like this: OnValueChangeClientScript="validateControlsUK()". Also, be aware, that Javascript is case sensitive. I don't know what is the function name in your javascript, but there is a difference between ValidateControlsUK and validateControlsUK. :) If that didn't work, here are some advice, how to troubleshoot: 1. You could try this line, to see if it's even a valid event you are trying to catch: OnValueChangeClientScript="javascript:alert('Date changed');" 2. If step 1 succeeds, you should put in your function, validateControlsUK, at the very beginning of it, a similar alert as above. This way you will know at least that your client side validation is triggered, but it's ill-performing for other reasons.

I hope this helped.

share|improve this answer
Sorry that did not work. – Ishan Jul 7 '12 at 6:27

I used like this work for me EX:

<SharePoint:DateTimeControl ID="txtstartdate" AutoPostBack="true" CssClassTextBox="h25" DateOnly="true" runat="server" OnDateChanged="dateDateBorrowed_OnDateChanged" />SharePoint:DateTimeControl CssClassTextBox="h25"  AutoPostBack="true" ID="txttodate" DateOnly="true" runat="server" OnDateChanged="dateDateBorrowed_OnDateChanged" />

CS File

protected void dateDateBorrowed_OnDateChanged(object sender, EventArgs e)
        if (txtstartdate != null)
            //lblMessage.Text = "Hello";
            if (txtstartdate.SelectedDate > txttodate.SelectedDate)
                txttodate.SelectedDate = Convert.ToDateTime(txtstartdate.SelectedDate);
            }else if(txttodate.SelectedDate < txtstartdate.SelectedDate )
                txtstartdate.SelectedDate = Convert.ToDateTime(txttodate.SelectedDate);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.