Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8365771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:44:26+00:00 2026-06-09T12:44:26+00:00

Inside the Views -> Shared folder I have the DateTime.ascx partial view; <%@ Control

  • 0

Inside the Views -> Shared folder I have the DateTime.ascx partial view;

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>
<%:Html.TextBox("", (Model.HasValue ? Model.Value.ToLongDateString() : string.Empty), 
    new { @class = "datePicker" })%>

This works in most of my application thanks to the jquery library http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js and this javascript code;

        // noWeekendsOrHolidays
        //  beforeShowDay: $.datepicker.noWeekends
        $(function () {
            $(".datePicker").datepicker({ showOn: 'both', dateFormat: 'dd MM yy', changeMonth: true, changeYear: true, yearRange: 'c-1:c+1', beforeShowDay: noWeekendsOrHolidays });
        });

I have a view as follows;

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master" 
Inherits="System.Web.Mvc.ViewPage<SHP.WebUI.Models.BankHolidayViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    BankHoliday
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <% using (Html.BeginForm("Create", "BankHoliday"))
       {%>
       <%: Html.AntiForgeryToken() %>
        <h3>Bank Holiday Administration</h3>
        <% if (TempData["UpdatedFlag"].ToString() == "True")
        { %>
        <p class="success">At time <% Response.Write(DateTime.Now.ToString("T")); %> - Details have been successfully saved 
            </p>
        <%}
        else if (TempData["UpdatedFlag"].ToString() == "False")
        {%>
        <p class="error">At time <% Response.Write(DateTime.Now.ToString("T")); %> - ERROR! Invalid date entered has NOT been saved 
            </p>
        <%} %>        
             <p>Select the year: <%: Html.DropDownListFor(model => model.SelectedYear, Model.YearList)%></p>
            <fieldset>
            <legend>Enter the bank holidays here:</legend>
             <p><i>You can find the bank holiday dates on this <a target="_blank" href="http://www.year-planner-calendar.wanadoo.co.uk/">website</a>.</i> </p>      
            <table class="groupBorder">
                <tr>
                    <th>Bank Holiday</th>
                    <th>Date</th>
                    <th>Notes</th>
                </tr>
                <%: Html.EditorFor(x => x.BankHolidays) %>
                <tr>
                    <td colspan="3" style="padding-top:20px;text-align: center">
                        <input type="submit" value="Save" id="btnSubmit"/>
                    </td>
                </tr>
            </table>
            </fieldset>
        <% } %>
        <script language="javascript" type="text/javascript">
            $(function () {
                $("#SelectedYear").change(function () {
                    var year = $("#SelectedYear").val();
                    $("#wholepage").load('<%:Url.Content(@"~/BankHoliday/Create/")%>' + year);
                });
            });
    </script>
</asp:Content>

In here you can see the line: <%: Html.EditorFor(x => x.BankHolidays) %>
This has an associated Editor Template;

” %>

<tr>
    <td><%: Model.T.BankHolidayDescription%>
        <%: Html.HiddenFor(model => model.BH.BankHolidayId) %>
        <%: Html.HiddenFor(model => model.T.BankHolidayTypeId) %>
    </td>
    <td><%: Html.EditorFor(model => model.BH.NullableBankHolidayDate)%></td>
    <td><%: Html.EditorFor(model => model.BH.BankHolidayComment)%></td>
</tr>

The date picker needs to apply to <%: Html.EditorFor(model => model.BH.NullableBankHolidayDate)%>

However it does not work. I click on the field and nothing happens.

When I press F12 and go into Developer Tools, I find the HTML for the control with the DatePicker looks like;

<input name="BankHolidays[6].BH.NullableBankHolidayDate" class="datePicker hasDatepicker" id="BankHolidays_6__BH_NullableBankHolidayDate" type="text" jQuery1341928330742="131"/>

So the class has been assigned to datePicker, so surely it should work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:44:28+00:00Added an answer on June 9, 2026 at 12:44 pm

    The problem was that I was populating the grid from an Ajax call, and the $(document).ready(function () {}) event did not fire.
    When I changed the code to submit to a POST action and populate the grid from that, it worked.
    I have have assigned the datepicker in a success function after the Ajax call, but I could not get that to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have _Layout.cshtml defined for my mvc application, which is shown below: @inherits System.Web.Mvc.WebViewPage
I have three table views inside a view controller (going to show/hide table views
I have a view that has multiple views inside it, and an image presentation
I have a form, with a partial view inside it to render several child
I'm currently developing a site using ASP.Net MVC3 with Razor. Inside the View/Shared folder,
Can I have a Shared Views directory inside a Area where I can put
So I have this ascx (partialView) control - ControlTemp I have an ajax.BeginForm inside
I have 2 instances of a user control (ascx) in a view page. I
I have some javascript and c# code inside one of my views that is
I currently have a tableview, with cell views which have NSTextFields inside of them.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.