如何在服务器控件中实现Ajax Calendar Extender?

时间:2022-09-02 13:33:23

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

我已经创建了一个服务器控件。在CreateChildControls事件中,我有一个文本框。我想使用Ajax Calendar Extender将此文本框更改为日历选择器,但到目前为止我没有工作...

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

我已经在控件被占用的页面中有一个AjaxScriptManager,所以没有添加另一个(以及当我这样做时出现'重复脚本管理器'错误的错误)。

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?

当我使用设计器在页面上添加日历时,我能够正常工作,而不是在服务器控件中...我错过了什么吗?

2 个解决方案

#1


0  

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

}

#2


0  

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

我使用Chrome来检查javascript是否全部有序,结果发现我收到了javascript错误。

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

这个网站也使用Telerik Rad控件并使用RadScriptManager而不是其他RAD控件的AjaxScriptManager ...而且不幸的是AJAX日历扩展器和RadScriptManager不兼容(不管我的版本不是)...所以我只是交换到使用RadDatePicker,看起来工作得很好......

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

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

#1


0  

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

}

#2


0  

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

我使用Chrome来检查javascript是否全部有序,结果发现我收到了javascript错误。

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

这个网站也使用Telerik Rad控件并使用RadScriptManager而不是其他RAD控件的AjaxScriptManager ...而且不幸的是AJAX日历扩展器和RadScriptManager不兼容(不管我的版本不是)...所以我只是交换到使用RadDatePicker,看起来工作得很好......

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

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