It is possible to add 'None' option in ajax toolkit calendar extender?

倖福魔咒の 提交于 2020-01-03 17:05:50

问题


I have an <ajaxToolkit:CalendarExtender> object in my page. It puts the selected date on a disabled TextBox (populated at start with the today date). I would want a 'None' option in that calendar, for which the system would do a default operation (like it has the Today option). Is this possible? I searched information about this on the Internet, but I couldn't find anything relevant. I wonder if I missed something. Or do I have to implement a separate logic (like enabling the TextBox and the user could leave it blank as a 'None' selection)?

Are there any calendar objects, different from ajax toolkit calendar extender, that can be used with asp.net that offer a 'None' option?

I am still opened for an answer even thought it's just a 'No' (at least a little documented).


回答1:


There are two options available: the first one is to add some html element next to textbox and handle it click event in javascript. In this event handler clear calendar extender. This is a code:

 <script type="text/javascript">
      function clearDate(extenderId) {
           $find(extenderId).set_selectedDate(null);
      }
 </script>

<asp:TextBox runat="server" ID="Date1" autocomplete="off" />
<input type="button" value="x" onclick="clearDate('<%= defaultCalendarExtender.ClientID %>')" /> 
<br />
<ajaxToolkit:CalendarExtender ID="defaultCalendarExtender" runat="server" 
    TargetControlID="Date1" />

And the second solution - to tweak sources of the AjaxControlToolkit project. Actually, you need to change only the Client/MicrosoftAjax.Extended/Calendar/CalendarBehavior.pre.js file. Replace it with code below. There is a lot of code actually because I'm too lazy to explain each change step-by-step ;) In brief I had add new element to calendar popup footer to reset selected date to default selected value if it was specified or to null. You may tweak also the Calendar.css file next to CalendarBehavior.pre.js

Due to limitation on huge answers I had post javascript code on pastebin Pastebin link



来源:https://stackoverflow.com/questions/12054369/it-is-possible-to-add-none-option-in-ajax-toolkit-calendar-extender

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!