1

I am having a datetime control in sharepoint custom webpart

<SharePoint:DateTimeControl 
        runat="server" 
        ID="txtUKdtofAdm" 
        LocaleId="2057" 
        DateOnly="True"
        OnValueChangeClientScript="validateControlsUK();" 
        AutoPostBack="true" 
        OnDateChanged="txtUKdtofAdm_OnDateChanged">
</SharePoint:DateTimeControl>

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.

0

3 Answers 3

0

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

-1

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.

1
  • Sorry that did not work.
    – Ishan
    Commented Jul 7, 2012 at 6:27
-2

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);
            }
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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