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 690773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:28:15+00:00 2026-05-14T02:28:15+00:00

How do I properly register javascript blocks in an ASP.NET MVC 2 (RTM) Editor

  • 0

How do I properly register javascript blocks in an ASP.NET MVC 2 (RTM) Editor template?

The specific scenario I’m in is that I want to use Dynarch JSCal2 DateTimePicker for my standard datetime picker, but this question is in general to any reusable javascript package. I have my template working properly now but it has my JS and CSS includes in my master page and I would rather only include these things if I actually need them:

<link rel="stylesheet" type="text/css" href="../../Content/JSCal2-1.7/jscal2.css" />
<link rel="stylesheet" type="text/css" href="../../Content/JSCal2-1.7/border-radius.css" />
<script type="text/javascript" src="../../Scripts/JSCal2-1.7/jscal2.js"></script>
<script type="text/javascript" src="../../Scripts/JSCal2-1.7/lang/en.js"></script>

So obviously I could just put these lines into my template, but then if I have a screen that has 5 DateTimePickers, then this content would be duplicated 5 times which wouldn’t be ideal. Anyways, I still want my View’s Template to trigger this code being put into the <head> of my page.

While it is completely unrelated to my asking this question, I thought I’d share my template on here (so far) in case it’s useful in any way:

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

<%= Html.TextBoxFor(model => Model) %>
<input type="button" id="<%= ViewData.TemplateInfo.GetFullHtmlFieldId("cal-trigger") %>" value="..." />

<script type="text/javascript">
    var <%= ViewData.TemplateInfo.GetFullHtmlFieldId("cal") %> = Calendar.setup({
        trigger       : "<%= ViewData.TemplateInfo.GetFullHtmlFieldId(string.Empty) %>",
        inputField    : "<%= ViewData.TemplateInfo.GetFullHtmlFieldId(string.Empty) %>",
        onSelect      : function() { this.hide(); },
        showTime      : 12,
        selectionType : Calendar.SEL_SINGLE,
        dateFormat    : '%o/%e/%Y %l:%M %P'
    });
</script>
  • 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-05-14T02:28:15+00:00Added an answer on May 14, 2026 at 2:28 am

    I usually add a script placeholder in my master page that is overridden by views:

    Master:

    <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
        <title></title>
        <asp:ContentPlaceHolder ID="Styles" runat="server" />
    </head>
    <body>
        <asp:ContentPlaceHolder ID="MainContent" runat="server" />
        <script type="text/javascript" src="scriptAvailableToAllPages.js"></script>
        <asp:ContentPlaceHolder ID="Scripts" runat="server" />
    </body>
    </html>
    

    View:

    <%@ Page Language="C#" 
             MasterPageFile="~/Views/Shared/Site.Master" 
             Inherits="System.Web.Mvc.ViewPage<Ns.MyModel>" %>
    
    <asp:Content ID="indexScripts" ContentPlaceHolderID="Scripts" runat="server">
        <script type="text/javascript" src="specific.js"></script>
    </asp:Content>
    
    <asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
        <% using (Html.BeginForm()) { %>
            <%= Html.EditorFor(x => x.Date1) %>
            <%= Html.EditorFor(x => x.Date2) %>
            <%= Html.EditorFor(x => x.Date3) %>
            <input type="submit" value="OK" />
        <% } %>
    </asp:Content>
    

    Notice how the editor template is included for three different properties of the model but the required scripts are included only once.

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

Sidebar

Related Questions

I use ASP.NET MVC 3 Razor, with jquery validation plugin to build a Registration
I have an app, modelled on the one from Apress Pro ASP.NET MVC that
How can I register a javascript code a page? I want to put th
I've written a Data Extender class and editor extension that properly displays a few
I've got an ASP.Net page in which I have an html anchor tag and
This article claims that each register has an intended purpose and more importantly, When
I'm writing a chunk of assembly that will register a tsr and then exit.
Okay so I've noticed that even though I use the correct path for the
I've got an image that I want to display as it does on the
Situation: A PHP Templating system that is responsible for building a pages HTML. Javascript

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.