Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI DatePicker image not showing

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") %>' />
like image 991
ProfK Avatar asked Dec 05 '25 07:12

ProfK


2 Answers

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

like image 116
jim tollan Avatar answered Dec 07 '25 20:12

jim tollan


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

like image 23
ravi Avatar answered Dec 07 '25 21:12

ravi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!