如何设置Datepicker VS 2013 [英] How to set up Datepicker VS 2013

查看:132
本文介绍了如何设置Datepicker VS 2013的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以给我一些具体的步骤让日期选择工作在 VS 2013 中工作?从包管理器,我安装了Bootstrap Datepicker1.3.0包。怎么办?我不能为我的生活找到任何文件,正是我需要做的,以使这个事情工作。



在我安装了软件包之后,我将引用引导到datepicker.js拖到页面的头部:

 < script src =../../../ Scripts / bootstrap-datepicker.js>< / script> 

我不知道这是我应该做的还是不做的。 VS 2013 将所有这些令人毛骨悚然的事情都与脚本捆绑在一起,而且我完全没有任何线索,如果这个过程影响了我如何获得日期戳记工作。



对于测试,我将此控件放在我的页面上:

 < input id =workDatetype = textvalue =06-01-2014class =dp/> 

我把这个放在我的页面上:

  $(function()
{
$('。dp')。datepicker({format:'mm-dd-yyyy'});
});

当我运行该页面时,我收到此错误:错误:对象不支持属性或方法'datepicker'。当然,我已经google了这个,发现了数十亿的帖子,但是我无法弄清楚在VS 2013中应该做什么 。许多这些说明了各种事情的加载,并经常引用不同版本的Visual Studio等。



看起来像JQuery或JQueryUI或者其他还有一个某些日期我不在乎我是否使用了Bootstrap或者一个JQuery,我只是不知道这两个过程是什么,或者如何弄清楚它们是否相互冲突等等。这真的让google当我甚至不能弄清楚谁的日期标记是谁指的。



这是一个Web应用程序项目,我使用母版页,EF 6.0,动态数据等等我已经安装了JQuery 2.1.0。



更新:
好​​吧,VS只是一个花哨的文本编辑器,我得到这个,我并不完全不同意。我的问题是,当您使用它创建一个Web应用程序时,它创建了几十个文件,并引用了遍布整个地方的东西。当我被告知只要确保你的参考是正确的顺序这是EXACT的事情,我无法弄清楚如何做。



这里有一些细节(我现在可能会被提供太多细节):

  BundleConfig.cs 

public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle(〜/ bundles / WebFormsJs)。Include(
〜/ Scripts / WebForms / WebForms.js,
〜/ Scripts / WebForms / WebUIValidation.js,
〜/ Scripts / WebForms / MenuStandards.js,
〜/ Scripts / WebForms / Focus.js,
〜/ Scripts / WebForms / GridView.js,
〜/ Scripts / WebForms / DetailsView.js,
〜/脚本/ WebForms / TreeView.js,
〜/ Scripts / WebForms / WebParts.js));

bundles.Add(new ScriptBundle(〜/ bundles / MsAjaxJs)。包含(
〜/ Scripts / WebForms / MsAjax / MicrosoftAjax.js,
〜 / scripts / WebForms / MsAjax / MicrosoftAjaxWebForms.js);)。

bundles.Add(new ScriptBundle(〜/ bundles / modernizr)。Include(
〜/ Scripts / modernizr- *));

ScriptManager.ScriptResourceMapping.AddDefinition(
respond,
new ScriptResourceDefinition
{
Path =〜/ Scripts / respond.min.js ,
DebugPath =〜/ Scripts / responses.js,
});

bundles.Add(new StyleBundle(〜/ StyleSheets)。IncludeDirectory(〜/ Content,* .css));
}
}

我不会撒谎 - 我不知道这里发生了什么,这个文件是由VS生成的。这是哪里我应该引用引导的datepicker.js(而不是单个页面的头)?

  Site.Master 

< head runat =server>
< meta charset =utf-8/>
< meta name =viewportcontent =width = device-width,initial-scale = 1.0/>
< title><%:Page.Title%> - 人力< / title>

< asp:PlaceHolder runat =server>
<%:Scripts.Render(〜/ bundles / modernizr)%>
< / asp:PlaceHolder>

< link href =../ Content / bootstrap-theme.css =stylesheet/>
< link href =../ Content / bootstrap.css =stylesheet/>
< link href =../ Content / DD.css =stylesheet/>
< link href =../ Content / Site.css =stylesheet/>

< link href =〜/ favicon.ico =快捷图标type =image / x-icon/>
< asp:ContentPlaceHolder ID =cpHeadrunat =server>
< / asp:ContentPlaceHolder>
< / head>

< body>
< form runat =服务器>
< asp:ScriptManager runat =server>
<脚本>
<% - 框架脚本 - %>
< asp:ScriptReference Name =MsAjaxBundle/>
< asp:ScriptReference Name =jquery/>
< asp:ScriptReference Name =bootstrap/>
< asp:ScriptReference Name =respond/>
< asp:ScriptReference Name =WebForms.jsAssembly =System.WebPath =〜/ Scripts / WebForms / WebForms.js/>
< asp:ScriptReference Name =WebUIValidation.jsAssembly =System.WebPath =〜/ Scripts / WebForms / WebUIValidation.js/>
< asp:ScriptReference Name =MenuStandards.jsAssembly =System.WebPath =〜/ Scripts / WebForms / MenuStandards.js/>
< asp:ScriptReference Name =GridView.jsAssembly =System.WebPath =〜/ Scripts / WebForms / GridView.js/>
< asp:ScriptReference Name =DetailsView.jsAssembly =System.WebPath =〜/ Scripts / WebForms / DetailsView.js/>
< asp:ScriptReference Name =TreeView.jsAssembly =System.WebPath =〜/ Scripts / WebForms / TreeView.js/>
< asp:ScriptReference Name =WebParts.jsAssembly =System.WebPath =〜/ Scripts / WebForms / WebParts.js/>
< asp:ScriptReference Name =Focus.jsAssembly =System.WebPath =〜/ Scripts / WebForms / Focus.js/>
< asp:ScriptReference Name =WebFormsBundle/>
<% - 网站脚本 - %>
< / Scripts>
< / asp:ScriptManager>

同样,这是由VS创建的自动生成的文件。这里有许多脚本的引用 - 这是我应该添加引用引用datepicker.js的参考,如果是,那么这行的确切语法是什么?

  Global.asax.cs 

void Application_Start(object sender,EventArgs e)
{
//在应用程序上运行的代码启动
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}

此文件中没有什么太有趣,但这是VS 2013似乎不同从其他版本 - 它捆绑的方式似乎已经改变或者某些东西。

  Packages.config 

<?xml version =1.0encoding =utf-8?>
< packages>
< package id =Antlrversion =3.5.0.2targetFramework =net451/>
< package id =AspNet.ScriptManager.bootstrapversion =3.1.1targetFramework =net451/>
< package id =AspNet.ScriptManager.jQueryversion =2.1.0targetFramework =net451/>
< package id =bootstrapversion =3.1.1targetFramework =net451/>
< package id =Bootstrap.Datepickerversion =1.3.0targetFramework =net451/>
< package id =DynamicDataTemplatesCSversion =1.0.1targetFramework =net451/>
< package id =EntityFrameworkversion =6.1.0targetFramework =net451/>
< package id =jQueryversion =2.1.0targetFramework =net451/>
< package id =Microsoft.AspNet.DynamicData.EFProviderversion =6.0.0targetFramework =net451/>
< package id =Microsoft.AspNet.EntityDataSourceversion =6.0.0targetFramework =net451/>
< package id =Microsoft.AspNet.FriendlyUrlsversion =1.0.2targetFramework =net451/>
< package id =Microsoft.AspNet.FriendlyUrls.Coreversion =1.0.2targetFramework =net451/>
< package id =Microsoft.AspNet.Identity.Coreversion =2.0.1targetFramework =net451/>
< package id =Microsoft.AspNet.Identity.EntityFrameworkversion =2.0.1targetFramework =net451/>
< package id =Microsoft.AspNet.Identity.Owinversion =2.0.1targetFramework =net451/>
< package id =Microsoft.AspNet.Providers.Coreversion =2.0.0targetFramework =net451/>
< package id =Microsoft.AspNet.ScriptManager.MSAjaxversion =5.0.0targetFramework =net451/>
< package id =Microsoft.AspNet.ScriptManager.WebFormsversion =5.0.0targetFramework =net451/>
< package id =Microsoft.AspNet.Web.Optimizationversion =1.1.3targetFramework =net451/>
< package id =Microsoft.AspNet.Web.Optimization.WebFormsversion =1.1.3targetFramework =net451/>
< package id =Microsoft.Owinversion =2.1.0targetFramework =net451/>
< package id =Microsoft.Owin.Host.SystemWebversion =2.1.0targetFramework =net451/>
< package id =Microsoft.Owin.Securityversion =2.1.0targetFramework =net451/>
< package id =Microsoft.Owin.Security.Cookiesversion =2.1.0targetFramework =net451/>
< package id =Microsoft.Owin.Security.Facebookversion =2.1.0targetFramework =net451/>
< package id =Microsoft.Owin.Security.Googleversion =2.1.0targetFramework =net451/>
< package id =Microsoft.Owin.Security.MicrosoftAccountversion =2.1.0targetFramework =net451/>
< package id =Microsoft.Owin.Security.OAuthversion =2.1.0targetFramework =net451/>
< package id =Microsoft.Owin.Security.Twitterversion =2.1.0targetFramework =net451/>
< package id =Microsoft.Web.Infrastructureversion =1.0.0.0targetFramework =net451/>
< package id =Modernizrversion =2.7.2targetFramework =net451/>
< package id =Newtonsoft.Jsonversion =6.0.3targetFramework =net451/>
< package id =Owinversion =1.0targetFramework =net451/>
< package id =Respondversion =1.4.2targetFramework =net451/>
< package id =System.Linq.Dynamicversion =1.0.0targetFramework =net451/>
< package id =WebGreaseversion =1.6.0targetFramework =net451/>
< / packages>

另一个自动生成的VS文件。不知道这是否是犹太人。



希望有人可以在某个地方找到某种方式帮助我解决问题的地方。因为我在这个版本中遇到了很多问题(没有一些调整),所以我希望有人解决了类似的问题。我只是不明白软件包管理器是什么意思,如果你仍然需要通过并将所有这些文件全部删除,以使事情能够正常工作 - 不应该解决依赖关系吗?



提前感谢所有这些内容。

解决方案

我正在回答这个问题帮助下一个可怜的buger,遇到这个STUPID问题。



我创建了一个新的VS应用程序和一个基本的(非主页面)的Web表单。因此:

 <%@ Page Language =C#AutoEventWireup =trueCodeBehind =TestDatePicker.aspx.cs Inherits =mptest.TestDatePicker%> 

<!DOCTYPE html>

< html xmlns =http://www.w3.org/1999/xhtml>
< head runat =server>
< title>< / title>
< link href =Site.css =stylesheet/>
< script src =Scripts / jquery-1.7.1.js>< / script>
< script src =Scripts / bootstrap.js>< / script>
< link href =Content / bootstrap.css =stylesheet/>
< script src =Scripts / bootstrap-datepicker.js>< / script>
< link href =Content / bootstrap-datepicker.css =stylesheet/>
< / head>
< body>
< form id =form1runat =server>
< div>< input id =StartDateclass =datepicker/>< / div>
< / form>
< / body>

< script type =text / javascript>
$('。datepicker')。datepicker();
< / script>

< / html>

毫不奇怪,它的工作完美。



然后我创建了一个简单的页面:

 <%@页面标题=语言=C#MasterPageFile = 〜/ Site.masterAutoEventWireup =trueCodeBehind =TestDatePickerMasterPage.aspx.csInherits =mptest.TestDatePickerMasterPage%> 

< asp:Content ID =Content1ContentPlaceHolderID =headrunat =server>< / asp:Content>

< asp:Content ID =Content2ContentPlaceHolderID =ContentPlaceHolder1runat =server>
< input id =StartDateclass =datepicker/>
< / asp:Content>

根据这个主页(再次VS卡住了所有的ScriptManager垃圾,我没有) :

 <%@ Master Language =C#CodeBehind =Site.master.csInherits =mptest.Site %> 

<!DOCTYPE html>

< html xmlns =http://www.w3.org/1999/xhtml>
< head runat =server>
< title>动态数据站点< / title>
< link href =〜/ Site.css =stylesheettype =text / css/>

< script src =Scripts / jquery-1.7.1.js>< / script>
< script src =Scripts / bootstrap.js>< / script>
< link href =Content / bootstrap.css =stylesheet/>
< script src =Scripts / bootstrap-datepicker.js>< / script>
< link href =Content / bootstrap-datepicker.css =stylesheet/>

< asp:ContentPlaceHolder ID =headrunat =server>
< / asp:ContentPlaceHolder>
< / head>
< body>
< form id =form1runat =server>
< div>
< asp:ScriptManager runat =serverEnablePartialRendering =false>
<脚本>
< asp:ScriptReference Name =jquery/>
< asp:ScriptReference Name =WebUIValidation.jsAssembly =System.Web/>
< / Scripts>
< / asp:ScriptManager>

< asp:ContentPlaceHolder ID =ContentPlaceHolder1runat =server>< / asp:ContentPlaceHolder>
< / div>
< / form>
< / body>

< script type =text / javascript>
$('。datepicker')。datepicker();
< / script>

< / html>

它立即失败了所有太熟悉的错误:对象不支持属性或方法'datepicker'消息。当我比较两个页面的浏览器源时,我注意到在基于母版的页面中有两个对jquery的引用。因此,我在主页面中注释掉了以下行:

 < asp:ScriptReference Name =jquery/> 

现在它工作得很好。



我仍然完全不知道这一切是什么意思,或者我可能通过删除这一行可能破坏,但解决了这一点。


Can anyone please give me some specific steps to get a date picker working in VS 2013? From the package manager, I installed the package "Bootstrap Datepicker" 1.3.0. Now what? I can't for the life of me find any documentation on what, exactly, I need to do to get this thing working.

After I installed the package, I dragged a reference to bootstrap-datepicker.js onto the head section of my page:

<script src="../../../Scripts/bootstrap-datepicker.js"></script>

I'm not sure if that's what I'm supposed to do or not). VS 2013 has all these murky things going on with script bundling and whatnot and I have absolutely no clue how/if this process affects how I get a datepicker working.

For testing, I placed this control on my page:

<input id="workDate" type="text" value="06-01-2014" class="dp" />

And I placed this in my page:

$(function ()
{
  $('.dp').datepicker({format: 'mm-dd-yyyy'});
});

When I run the page, I get this error: "Error: Object doesn't support property or method 'datepicker'". Of course, I've googled this and found billions of postings, but I can't figure out what I'm supposed to do in VS 2013. Many of these talk about the order various things are loaded and frequently refer to vastly different versions of Visual Studio, etc.

It seems like JQuery or JQueryUI or whatever ALSO has a datepicker of some sort. I don't care if I use the Bootstrap one or the JQuery one, I just don't know what the procedure is for either one, or how to figure out if they're conflicting with each other, etc. This REALLY makes googling hard when I can't even figure out WHICH datepicker people are referring to.

This is a Web Application project, I'm using Master Pages, EF 6.0, Dynamic Data, etc. I have JQuery 2.1.0 installed.

UPDATE: Ok, VS is just a fancy text editor, I get that, and I don't disagree entirely. My problem is that when you create a web application with it, it creates dozens of files with references to things sprinkled all over the place. When I'm told "Just make sure your references are in the correct order" that's the EXACT thing I'm having trouble figuring out how to do.

Here's some detail (I'll probably get chastised now for providing too much detail):

BundleConfig.cs

public class BundleConfig
  {
    public static void RegisterBundles(BundleCollection bundles)
    {
      bundles.Add(new ScriptBundle("~/bundles/WebFormsJs").Include(
        "~/Scripts/WebForms/WebForms.js",
        "~/Scripts/WebForms/WebUIValidation.js",
        "~/Scripts/WebForms/MenuStandards.js",
        "~/Scripts/WebForms/Focus.js",
        "~/Scripts/WebForms/GridView.js",
        "~/Scripts/WebForms/DetailsView.js",
        "~/Scripts/WebForms/TreeView.js",
        "~/Scripts/WebForms/WebParts.js"));

      bundles.Add(new ScriptBundle("~/bundles/MsAjaxJs").Include(
        "~/Scripts/WebForms/MsAjax/MicrosoftAjax.js",
        "~/Scripts/WebForms/MsAjax/MicrosoftAjaxApplicationServices.js",
        "~/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js",
        "~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js"));

      bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
        "~/Scripts/modernizr-*"));

      ScriptManager.ScriptResourceMapping.AddDefinition(
        "respond",
        new ScriptResourceDefinition
        {
          Path = "~/Scripts/respond.min.js",
          DebugPath = "~/Scripts/respond.js",
        });

      bundles.Add(new StyleBundle("~/StyleSheets").IncludeDirectory("~/Content", "*.css"));
    }
}

I'm not gonna lie - I have no idea what's going on here, this file was generated by VS. Is this where I should be placing a reference to bootstrap-datepicker.js (rather than in the head of an individual page)?

Site.Master

<head runat="server">
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title><%: Page.Title %> - Manpower</title>

  <asp:PlaceHolder runat="server">
    <%: Scripts.Render("~/bundles/modernizr") %>
  </asp:PlaceHolder>

  <link href="../Content/bootstrap-theme.css" rel="stylesheet" />
  <link href="../Content/bootstrap.css" rel="stylesheet" />
  <link href="../Content/DD.css" rel="stylesheet" />
  <link href="../Content/Site.css" rel="stylesheet" />

  <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
  <asp:ContentPlaceHolder ID="cpHead" runat="server">
  </asp:ContentPlaceHolder>
</head>

<body>
  <form runat="server">
  <asp:ScriptManager runat="server">
    <Scripts>
      <%--Framework Scripts--%>
      <asp:ScriptReference Name="MsAjaxBundle" />
      <asp:ScriptReference Name="jquery" />
      <asp:ScriptReference Name="bootstrap" />
      <asp:ScriptReference Name="respond" />
      <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
      <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
      <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
      <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
      <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
      <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
      <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
      <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
      <asp:ScriptReference Name="WebFormsBundle" />
      <%--Site Scripts--%>
    </Scripts>
  </asp:ScriptManager>

Again, this is an auto-generated file created by VS. There are many references to scripts here - is this where I should be adding a reference to bootstrap-datepicker.js, and if so, what would be the exact syntax of the line?

Global.asax.cs

void Application_Start(object sender, EventArgs e)
{
  // Code that runs on application startup
  RouteConfig.RegisterRoutes(RouteTable.Routes);
  BundleConfig.RegisterBundles(BundleTable.Bundles);
}

Nothing too interesting in this file, but this is where VS 2013 seems to differ from other versions - the way it does bundling seems to have changed or something.

Packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.5.0.2" targetFramework="net451" />
  <package id="AspNet.ScriptManager.bootstrap" version="3.1.1" targetFramework="net451" />
  <package id="AspNet.ScriptManager.jQuery" version="2.1.0" targetFramework="net451" />
  <package id="bootstrap" version="3.1.1" targetFramework="net451" />
  <package id="Bootstrap.Datepicker" version="1.3.0" targetFramework="net451" />
  <package id="DynamicDataTemplatesCS" version="1.0.1" targetFramework="net451" />
  <package id="EntityFramework" version="6.1.0" targetFramework="net451" />
  <package id="jQuery" version="2.1.0" targetFramework="net451" />
  <package id="Microsoft.AspNet.DynamicData.EFProvider" version="6.0.0" targetFramework="net451" />
  <package id="Microsoft.AspNet.EntityDataSource" version="6.0.0" targetFramework="net451" />
  <package id="Microsoft.AspNet.FriendlyUrls" version="1.0.2" targetFramework="net451" />
  <package id="Microsoft.AspNet.FriendlyUrls.Core" version="1.0.2" targetFramework="net451" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.0.1" targetFramework="net451" />
  <package id="Microsoft.AspNet.Identity.EntityFramework" version="2.0.1" targetFramework="net451" />
  <package id="Microsoft.AspNet.Identity.Owin" version="2.0.1" targetFramework="net451" />
  <package id="Microsoft.AspNet.Providers.Core" version="2.0.0" targetFramework="net451" />
  <package id="Microsoft.AspNet.ScriptManager.MSAjax" version="5.0.0" targetFramework="net451" />
  <package id="Microsoft.AspNet.ScriptManager.WebForms" version="5.0.0" targetFramework="net451" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net451" />
  <package id="Microsoft.AspNet.Web.Optimization.WebForms" version="1.1.3" targetFramework="net451" />
  <package id="Microsoft.Owin" version="2.1.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="2.1.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Security" version="2.1.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Security.Cookies" version="2.1.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Security.Facebook" version="2.1.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Security.Google" version="2.1.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.1.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Security.OAuth" version="2.1.0" targetFramework="net451" />
  <package id="Microsoft.Owin.Security.Twitter" version="2.1.0" targetFramework="net451" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net451" />
  <package id="Modernizr" version="2.7.2" targetFramework="net451" />
  <package id="Newtonsoft.Json" version="6.0.3" targetFramework="net451" />
  <package id="Owin" version="1.0" targetFramework="net451" />
  <package id="Respond" version="1.4.2" targetFramework="net451" />
  <package id="System.Linq.Dynamic" version="1.0.0" targetFramework="net451" />
  <package id="WebGrease" version="1.6.0" targetFramework="net451" />
</packages>

Yet another auto-generated VS file. Not sure if this is kosher or not.

Hopefully someone can spot something somewhere that somehow helps me zero in on the problem. I keep harping on VS2013, because I have run across many problems with things that don't quite work in this version (without some tweaking), so I'm hoping someone has resolved a similar problem. I just don't understand what the point of the 'package manager' is, if you still have to go through and hack all these files to make things work - shouldn't it resolve dependencies for you?

Thanks in advance for wading through all this content.

解决方案

I'm answering this question to help the next poor bugger who runs into this STUPID problem.

I created a new VS application, and a basic (non-master-page) web form. Thusly:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestDatePicker.aspx.cs" Inherits="mptest.TestDatePicker" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <link href="Site.css" rel="stylesheet" />
  <script src="Scripts/jquery-1.7.1.js"></script>
  <script src="Scripts/bootstrap.js"></script>
  <link href="Content/bootstrap.css" rel="stylesheet" />
  <script src="Scripts/bootstrap-datepicker.js"></script>
  <link href="Content/bootstrap-datepicker.css" rel="stylesheet" />
</head>
<body>
  <form id="form1" runat="server">
    <div><input id="StartDate" class="datepicker" /></div>
  </form>
</body>

<script type="text/javascript">
  $('.datepicker').datepicker();
</script>

</html>

Not surprisingly, it worked perfectly.

I then created a simple page like this:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="TestDatePickerMasterPage.aspx.cs" Inherits="mptest.TestDatePickerMasterPage" %>

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

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <input id="StartDate" class="datepicker" />
</asp:Content>

Based on this master page (again VS stuck all the ScriptManager junk in there, I didn't):

<%@ Master Language="C#" CodeBehind="Site.master.cs" Inherits="mptest.Site" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>Dynamic Data Site</title>
  <link href="~/Site.css" rel="stylesheet" type="text/css" />

  <script src="Scripts/jquery-1.7.1.js"></script>
  <script src="Scripts/bootstrap.js"></script>
  <link href="Content/bootstrap.css" rel="stylesheet" />
  <script src="Scripts/bootstrap-datepicker.js"></script>
  <link href="Content/bootstrap-datepicker.css" rel="stylesheet" />

  <asp:ContentPlaceHolder ID="head" runat="server">
  </asp:ContentPlaceHolder>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <asp:ScriptManager runat="server" EnablePartialRendering="false">
        <Scripts>
          <asp:ScriptReference Name="jquery" />
          <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" />
        </Scripts>
      </asp:ScriptManager>

      <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>
    </div>
  </form>
</body>

<script type="text/javascript">
  $('.datepicker').datepicker();
</script>

</html>

It failed immediately with the all-too-familiar "Error: Object doesn't support property or method 'datepicker'" message. When I compared the browser source for the two pages, I noticed that there were two references to jquery in the masterpage-based one. Therefore, I commented out the following line in the master page:

<asp:ScriptReference Name="jquery" />

Now it works perfectly.

I still have absolutely no idea what this all means or what I'm potentially breaking by removing this line, but that solved it.

这篇关于如何设置Datepicker VS 2013的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆