4

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).

Coral Doe
  • 1,925
  • 3
  • 19
  • 36
  • No, but why not just let the user select nothing? You don't need to set the TextBox' Text to today. – Tim Schmelter Aug 21 '12 at 12:02
  • What if the user makes a date selection, but then changes his mind before submiting? The date is already selected in the calendar and he is forced to reload the page somehow. – Coral Doe Aug 21 '12 at 12:06
  • So why do you want to disable the TextBox at all? Don't restrict the user. If he wants to select a date, he can select it with the extender or enter it manually. If he don't want to select one, he can leave it blank or delete it if it was already selected. Another option is: you could provide a "clear-button" if you really want. – Tim Schmelter Aug 21 '12 at 12:39
  • In the end that might be what it remains using. At the moment I am still using o tooltip to say to the user that he may leave the TextBox blank to keep it as a 'None' option. But I am still investigating other ways of doing it. – Coral Doe Aug 28 '12 at 08:37

1 Answers1

2

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

Yuriy Rozhovetskiy
  • 22,270
  • 4
  • 37
  • 68
  • This is a great solution. Thank you. I have actually tried the second solution because it is more elegant and integrated (in my opinion). – Coral Doe Oct 18 '12 at 11:18