ASP.Net AJAX calendar - only allow the user to select Mondays

情到浓时终转凉″ 提交于 2019-12-11 09:06:26

问题


I have a ASP.NET AJAX Calender and a TextBox. I want the user should be able to select only Mondays from the calender as that is the business rule.

I can achieve this by using regular ASP.NET calendar control using the DayRender event, however I wish to use the AJAX Calender control because of its better appearance, easy navigation and partial postback.

How can I achieve this (selecting only Mondays) using ASP.NET AJAX calendar?


回答1:


You could only workaround by alert the user if he tries to select anything else than a Monday:

<script type="text/javascript">
    function checkDate(sender,args){
       if (sender._selectedDate.getDay() != 1){
           alert("You can only select Mondays!");
           sender._selectedDate = new Date(); //set back to current date
           sender._textbox.set_Value(sender._selectedDate.format(sender._format))
       }
    }
</script>


<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" 
   OnClientDateSelectionChanged="checkDate" TargetControlID="TextBox1" />


来源:https://stackoverflow.com/questions/6550007/asp-net-ajax-calendar-only-allow-the-user-to-select-mondays

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