0

Having Issue with AjaxCalendarExtenderControl.Add in ASP.NET

The following code:
Private Sub AddCalendarExtender() AddControlToCollection(AjaxCalendarExtenderControl.Add("Calendar" & QuestionCounter, ControlID, "Image" & QuestionCounter)) End Sub Tied to:

Namespace Survey.BusinessDelegate Public Class AjaxCalendarExtenderControl Public Sub New()

    Public Shared Function Add(ID As String, TargetControlID As String, ImageButtonID As String) As CalendarExtender
End Class

End Namespace Will not display calendar. Works on production server but not visual studio debugger. Does anyone have any ideas on how to get the Calendar to display?

Tried executing Ajaxcalendarextender code but it does not display calendar?

1 Answer 1

0

Are you sure you need or want to use the AjaxToolKit calendar extender?

You can turn any standard textbox into a calendar popup simply by setting text mode to Date.

Hence this markup:

        <h3>Enter date</h3>
        <asp:TextBox ID="TextBox1" runat="server"
            TextMode="Date">
        </asp:TextBox>

And the result is now this:

enter image description here

So, you can consider using the calendar extender from the AjaxToolKit, but it not clear if you need it anyway?

Also, I don't recommend using code to attach, or wire up the textbox to the AjaxToolKit using the date picker extender. In other words, why not just place the extender in the markup, and not worry about using code to attach or add the extender to the textbox?

If after deploying to production server, the AjaxToolKit extender does not work, then this suggests the AjaxToolKit is not installed correctly, or that your publishing process is not including the AjaxToolKit correctly when published to the production server.

Edit: Using code behind to set the text box

To set a textbox, as correctly pointed out in comments below, you have to feed the text box the ISO date format.

Hence, this typical code can be used to set some default value for a text box

        Dim MyDate As DateTime = Date.Today

        txtDate.Text = MyDate.ToString("yyyy-MM-dd")

Keep in mind that the resulting display can be near any format, since what is displayed in the text box will be based on the user's regional settings on their computer.

6
  • This worked. I removed the calendar extender and added a textbox with date mode and this solved the problem! Thanks!
    – dibello.4
    Commented Jul 3 at 19:48
  • Only advantage of the AJ date picker extender is it has the built in ability to call a server side web method (thus avoiding a full page post back). However, you can also with the standard text box set autopost-back = true, and then for server side code use the on text changed event. So, about the only advantage of the AJ date picker extender is it is "easier" to call a server side code stub and do so without a post back. Other then this advantage, I think using the built in date, datetime, or time picker works rather well (and they ALL do show a nice icon to click on). Commented Jul 3 at 21:16
  • Date mode is working but I need to display the date in this format yyyymmdd using this code : Does anyone know how to do this? traditional formatting methods are not working: Public Shared Function TextBoxControl2(ByVal ID As String, ByVal questionDTO As Survey.DataTransferObjects.QuestionDTO) As System.Web.UI.WebControls.TextBox Dim tb As System.Web.UI.WebControls.TextBox = Add(ID, questionDTO) tb.TextMode = TextBoxMode.Date Return tb End Function
    – dibello.4
    Commented Jul 8 at 17:46
  • The date format is set and controlled by the end user's desktop and browser setting. So, the date format is based on the client side user "regional" settings. For a text box, or even a GridView, you can format the date anyway you want. But, for a date control, or date picker, the format is controlled by the end user's settings, not the server side. So, if you want that format to change, then you need to ask the user to change their windows desktop regional settings, and under that, they can set the date format. For your server side code, just assign the text box a valid datetime variable. Commented Jul 9 at 17:56
  • That's not true. The ASP.NET textbox Date control needs to be set to yyyy/mm/dd. This is a code change not a settings change. Does anyone know what to do this?
    – dibello.4
    Commented Jul 10 at 19:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.