简体   繁体   中英

How do I implement Ajax Calendar Extender in Server Control?

I have created a server control.
In the CreateChildControls event, I have a textbox. I would like to change this textbox to a calendar picker using the Ajax Calendar Extender, but what I have so far is not working...

private TextBox _txtStartDate;
private CalendarExtender _calExTxtStartDate;

protected override void CreateChildControls() {
... etc
_txtStartDate = new TextBox();
_txtStartDate.ID = "txtStartDate";

_calExTxtStartDate = new CalendarExtender();
_calExTxtStartDate.ID = "calExTxtStartDate";
_calExTxtStartDate.TargetControlID = "txtStartDate";
... etc
Controls.Add(_txtStartDate);
Controls.Add(_calExTxtStartDate); // Calendar Extender
... etc
}

I already have an AjaxScriptManager in the page that the control is consumed, so have not added another (and errors with a 'duplicate script manager' error when I do).

I am able to get this working when using the designer to add the calendar on a page, but not in the server control... Am I missing something?

I think you would have to do it as:

private TextBox _txtStartDate;
private CalendarExtender _calExTxtStartDate;

protected override void CreateChildControls() {
... etc
_txtStartDate = new TextBox();
Controls.Add(_txtStartDate);
_txtStartDate.ID = "txtStartDate";

_calExTxtStartDate = new CalendarExtender();
Controls.Add(_calExTxtStartDate); // Calendar Extender
_calExTxtStartDate.ID = "calExTxtStartDate";
_calExTxtStartDate.TargetControlID = _txtStartDate.ClientID;
... etc

}

I used Chrome to check that the javascript was all in order and it turns out I was getting javascript errors.

This website also makes use of Telerik Rad controls and uses RadScriptManager instead of AjaxScriptManager becsuae of other RAD controls... and unfortunately the AJAX calendar extender and RadScriptManager are not compatible (not in my versions anyway)... So I simply swapped over to use the RadDatePicker, which seems to work fine...

http://demos.telerik.com/aspnet-ajax/calendar/examples/datepicker/custompopup/defaultcs.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM