Hi,
How can I postback when I use the keyboard to change the value in the WebDatePicker? I know how to accomplish this by selecting from the calendar.
Thank you,
Trent
Hi Trent,
You may enable autopostback on enter key. Similar way can be triggered a postback on lost focus (value change). To trigger postback on other keys or events, application may process corresponding client side events (like KeyUp), check event/keyCode, check current value in editor (if it is valid and complete), etc, and call __doPostBack(sender.get_uniqueID(), '') or use similar statements.
Example for autopostback:
<ig:WebDatePicker ID="WebDatePicker1" runat="server"> <AutoPostBackFlags EnterKeyDown="On" /></ig:WebDatePicker>
Hi Viktor,
When I added the AutoPostBackFlags-EnterKeyDown="On", the value change from selecting the date on the calendar does not trigger the postback.
I'm using v12.1. This is what happens when I set both ValueChanged="On" and EnterKeyDown="On".
1. Enter date by keyboard will postback when I tab out, which is OK.
2. Select a date by calendar DOES NOT postback, until I click somewhere else. This doesn't seem correct. Shouldn't the postback occur after I select the date in the calendar?
Drop-down calendar is just a helper to enter year-month-date fields in pattern displayed in INPUT-field of datepicker. After selection in drop-down calendar edit mode continues and user may type something else (fill possible hour/minute/second fields). User also may select another date from calendar again. Edit mode stops only on lost focus. If at that time the value in editor before focus is not equal to the value after focus, then ValueChanged event is raised.
If in old version the ValueChanged was raised on close drop-down calendar, then that would be a bug (though, I do not remember similar issue).
If application needs to treat selection from calendar as ValueChanged and trigger postback, then as I suggested before, other events can be processed and explicit postback can be triggered. Below is example with CalendarClosed:
<script type="text/javascript">function WebDatePicker1_CalendarClosed(sender, eventArgs) { var oldVal = eventArgs.get_oldValue(), newVal = eventArgs.get_value(); if (newVal && (!oldVal || oldVal.getTime() !== newVal.getTime())) { sender.set_value(newVal); __doPostBack(sender.get_id(), 'ValueChanged'); }}</script><ig:WebDatePicker ID="WebDatePicker1" runat="server"> <ClientSideEvents CalendarClosed="WebDatePicker1_CalendarClosed" /> <AutoPostBackFlags EnterKeyDown="On" ValueChanged="On" /></ig:WebDatePicker>
After I select a date, the calendar closes right away so I can't choose another date. Also, if my format in the field is just the date and no time, I don't see the need to keep it in edit mode. I can use the workaround, but maybe there could be a property to postback after calendar closes.
Thanks,
Hello Trent,
What I can suggest for achieving your requirement is handle WebDatePicker`s KeyDown event which is fired even when the DateTimePicker is on focus. In the event current text being entered is accessible via sender`s get_text() method as such: sender.get_text(); . Please note that string returned from this method contains everything visible in the input textbox of the DatePicker, including the slashes used to separate the date ("_2/__/____"). What I can suggest is take this string, split it by the slash("/") symbol and check whether the input is a valid date. If the input is a valid date a CallBackManager object for the WebDatePicker control may be executed to cause a PostBack as such:
var callbackObject = sender._callbackManager.createCallbackObject(); sender._callbackManager.execute(callbackObject);
var callbackObject = sender._callbackManager.createCallbackObject();
sender._callbackManager.execute(callbackObject);
I hope this helps.
Let me know if you have any questions.
I was wondering did you have a chance to try my suggestion? Please feel free to contact me if you have any additional questions regarding this matter.
Thank you for your feedback. I am glad that you managed to resolve the issue.
We value your input, and our philosophy is to enhance our toolset based on customer feedback.
Please let me know if I can be of any further assistance.
Hi Vasya,
I managed to get it working by adding the Javascript. However, I don't feel that is the right solution. I used Infragistics control because it is suppose to write all that code for me. Why should I enable something to postback and then have to write the Javascript code to postback.