views:

77

answers:

2

I have the following init code for the datepicker, but the default 'Choose Date' link is displayed, not the image. This is in an MVC project, but that shouldn't affect anything to the best of my knowledge.

    $(function () {
        $(".date-picker").datePicker({
            showOn: 'both',
            dateFormat: 'dd-mm-yy',
            changeMonth: true,
            changeYear: true,
            showOn: 'button', 
            buttonImage: '<%= Url.Content("~/Content/images/date_picker2.gif") %>',
    });

The rendered buttonImage option looks like this:

buttonImage: '/Content/images/date_picker2.gif',

An img tag like this renders the image correctly:

<img src='<%= Url.Content("~/Content/images/date_picker2.gif") %>' />
+1  A: 

ProfK - i use the datepicker inside a shared EditorTemplate and my code looks very similar to the above. here's what I have under Views->Shared->EditorTemplates->DateTime.ascx:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime?>" %>

<%string name = ViewData.TemplateInfo.HtmlFieldPrefix;%>
<%string id = name.Replace(".", "_");%>

<div class="editor-label">
    <%= Html.LabelFor(model => model) %>
</div>
<div class="editor-field">
    <%= Html.TextBox("", (Model.HasValue ? Model.Value.ToString("dd-MM-yyyy") : string.Empty), new { @class = "date" }) %>
    <%= Html.ValidationMessageFor(model => model)%>
</div>      

<script type="text/javascript">
    $(document).ready(function() {
        $("#<%=id%>").datepicker({
            dateFormat: 'dd-mm-yy',
            changeMonth: true,
            changeYear: true,
            showOn: 'button', 
            buttonImage: '<%=Url.Content("~/Content/images/calendar.gif") %>'
        });
    });
</script>

[edit] - usage in view:

<%= Html.EditorFor(m => m.StartDate) %>

give it a try, see if it helps out any...

jim

jim
You have `showOn` defined twice ;)
Nick Craver
oops, so i have!! - fixed
jim
Thanks @jim, your EditorTemplate is working nicely, but in haste yesterday, the jQuery part wasn't, so that's been delegated to the master page. I'll check it again later today.
ProfK
+2  A: 

Use firefox and install the firebug extension. And monitor the network tab for any errors.

ravi
That indeed pointed me to another error with the same image later on, thanks.
ProfK