views:

1196

answers:

2

I'd like to use an ajaxToolkit:CalendarExtender on an asp:Label. When I attach a CalendarExtender to the label, I get the error:

Extender controls of type 'AjaxControlToolkit.CalendarExtender' cannot extend controls of type 'System.Web.UI.WebControls.Label'.

I'm hoping someone knows a quick trick to allow me to display a date in a label and allow that label to be clicked to trigger/open a CalendarExtender which might target a hidden asp:TextBox... if that's possible.

A: 

If you have the source code of AjaxControlToolkit you can edit CalendarExtender.cs and then change

[TargetControlType(typeof(TextBox))]

and put Label (or Control if you want to have only one calendar extender) . Don't know how that will afect general behaviour of the Extender.

MaLKaV_eS
+1  A: 

As the error states, the Calendar extender is constrained to extend only textbox controls by default.

Looking at the ASP.NET AJAX Control toolkit page for the Calendar extender, you should be able to use the PopupButtonID to enable the label to trigger the calendar popup (you'll need to add in the unhiding of the textbox too).

Russ Cam
I think this would be perfect .. but it seems like making the asp:TextBox visible=false prevents the calendar from appearing.
Adam Douglass
That's because setting visible = false in the aspx markup does not output the HTML on the server side to render the textbox on the client side. I would put some JavaScript in the client side function pageLoad() to hide the textbox when the page has loaded
Russ Cam
See here for the pageLoad - http://stackoverflow.com/questions/416363/javascript-function-should-be-running-on-every-page-load/416447#416447 and http://encosia.com/2007/08/01/simplify-aspnet-ajax-client-side-page-initialization/
Russ Cam
You'll want to set display = none on the textbox when the page has loaded
Russ Cam