To disable autopostback for Calender Control in ASP.net

后端 未结 4 693
广开言路
广开言路 2021-01-13 13:00

Iam trying to use System.Web.UI.WebControls.Calender.

But when I select any date , It post backs automatically. Is there any way to avoid this behavior.

(I d

相关标签:
4条回答
  • 2021-01-13 13:41
    • You cannot disable "Autopostback" of the Standard Calendar control
    • I think you can use CalendarExtender from AjaxToolkit

    <asp:TextBox ID="txtCalendarExtender" runat="server"></asp:TextBox> 
    <cc3:CalendarExtender ID="Calendar1" PopupButtonID="imgPopup" runat="server" TargetControlID="txtCalendarExtender" Format="dd/MM/yyyy"> 
    </cc3:CalendarExtender> 
    

    Remember to add this code at the top of your page:

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc3" %>
    

    Remember, there is a forum about this topic where PLBlum says:

    The Calendar control included with ASP.NET uses postbacks only. If you added Microsoft ASP.NET AJAX to the page and put the calendar into an UpdatePanel, it can reduce the appearance of postbacks by using callbacks. But it still makes a trip to the server for each click on a date or month.

    0 讨论(0)
  • 2021-01-13 13:44

    I generally avoid avoid the MS calender control because I find it so hard to work with and style. Have you considered something like the jQuery UI date picker, works as you need and far easier to style after too.

    http://jqueryui.com/demos/datepicker/#inline

    0 讨论(0)
  • 2021-01-13 13:44

    It is possible with MS Calendar. You can customize content of each cell in DayRender event:

    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            e.Cell.Text = e.Day.DayNumberText;
        }
    

    You can set e.Cell.Text to be div or span with text and javascript onclick event or link. You can put any HTML there.

    0 讨论(0)
  • 2021-01-13 13:49

    It posts back to set the selected form on the UI. what you can do is use a client side calendar (like jquery ui) or use ajax calendar extender so it will not postback the whole page.

    0 讨论(0)
提交回复
热议问题