To disable autopostback for Calender Control in AS

2020-03-24 06:13发布

问题:

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 dont see the usual property AutoPostback which I set to False to avoid this behavior)

I need the selected date only once user submits the form.

Note- I am using VS2008

回答1:

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



回答2:

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.



回答3:

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.



回答4:

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