如何在asp.net的母版页的内容页面中包含jQuery? [英] How to include jQuery inside a content page of a master page in asp.net?

查看:77
本文介绍了如何在asp.net的母版页的内容页面中包含jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了所有可能性(不是涉及从代码隐藏中添加js的那些)..



我有一个脚本,我想要包含在内容页面中..还有一个.js的参考。我想包括两者!



I have tried all the possibilities (not the ones involving adding js from codebehind)..

I have a script which I want to include in a content page.. There is a ref of .js also. I want to include both!

<script src="Scripts/js/jquery.slimscroll.min.js" type="text/javascript"></script>






and

<script> <!--Script to add scrollbar to the category boxes-->
$(function () {
    $('.catcontent').slimscroll({
        height: '180px',
        width: '100%',
        opacity: '.08',
        distance: '0px'
    }).parent().css({
        'float': 'left',
        'margin-right': '1px'
    });
});
</script>







我已经尝试了所有可能性,在母版页中添加了两者,内容页面在主页面和内容页面中的脚本中添加ref!因为我有一个非常弱的逻辑基础,浏览器如何检查脚本,因此无法实现我想要的目标!



如果我单独制作这个脚本工作正常aspx页面。将滚动条整齐地添加到




I have tried all the possibilities, added both in the master page, added both in the content page adding ref in the master page and script in the content page! Since I have a very weak logic base of how a browser checks the script so unable to achieve what I want to!

This script is working fine if I make a separate aspx page. Adds a scrollbar neatly to the

<div>

。但是当我试图在内容页面中添加它时,它无法正常工作!



当你回答这个问题时!请尝试解释一下最佳实践是什么以及如何实际添加!!我记得过去在内容页面中添加了css和js!但我有点失去联系,我尝试在互联网上搜索!今天没有什么对我有用!请帮我!谢谢



主页:



. But it is not working when I'm trying to add it inside a content page!

Also when you answer this! Please try and explain me what is the best practice and how to actually add it!! I remember of adding css and js to content pages in the past! But I was a little out of touch and I tried searching in the internet! Nothing worked for me today! Please help me! Thanks

Master page:

<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
    <!--CSS Stylesheets-->
    <link rel="stylesheet" type="text/css" href="~/Content/css/bootstrap-theme.min.css" />
    <link rel="stylesheet" type="text/css" href="~/Content/css/bootstrap.min.css" />
    <link rel="stylesheet" media="screen" href="~/Content//font-awesome/css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="~/Content/css/style.css" />
    <!-- Javascript -->
    <script src="~/Scripts/js/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="~/Scripts/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="Scripts/js/jquery.slimscroll.min.js" type="text/javascript"></script>


</head>
<body>
    <form id="form1" runat="server">
        <div>
<div class="container">
<p>ldlajdlkdjljda</p>
</div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>
        </div>
    </form>
</body>
</html>







内容页面:






Content Page:

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

    <header>
        <div class="container">
        </div>
    </header>
    <section class="category">
        <div class="container">
            <h2>Some text goes here</h2>
            <p>
                Some text goes here...Some text goes here...Some text goes here...
                Some text goes here...Some text goes here...Some text goes here...
                Some text goes here...Some text goes here...Some text goes here...
                Some text goes here...Some text goes here...Some text goes here...
                Some text goes here...Some text goes here...Some text goes here...
            </p>
            <span class="row" />
        </div>
        <div class="container content">
            <asp:DataList ID="DataListCategory" runat="server" DataKeyField="Pk_Category_Id" DataSourceID="SqlDataSourceCategory" RepeatDirection="Horizontal" RepeatColumns="4" Width="100%" CssClass="row" AlternatingItemStyle-HorizontalAlign="NotSet" RepeatLayout="Flow">
                <ItemTemplate>
                    <div class="col-sm-12 col-md-3 item">
                        <asp:Label runat="server" ID="CatID" Text='<%# Eval("Pk_Category_Id") %>' Visible="False" />
                        <h4><%# Eval("Category_Title") %></h4>
                        <div class="catcontent">
                            <ul>
                                <asp:DataList ID="DataListObjectivesList" runat="server" DataKeyField="Pk_Objective_Id" DataSourceID="SqlDataSourceObjectives">
                                    <ItemTemplate>

                                        <li>
                                            <asp:HyperLink ID="linkObjective" runat="server" Target="_blank"

                                                Text='<%# Eval("Title") %>'

                                                NavigateUrl='<%# "Objective.aspx?oid=" + Eval("Pk_Objective_Id")%>' />
                                        </li>
                                    </ItemTemplate>
                                </asp:DataList>
                            </ul>
                        </div>
                    </div>
                    <div>
                        <asp:SqlDataSource ID="SqlDataSourceObjectives" runat="server" ConnectionString="<%$ ConnectionStrings:ConString %>" SelectCommand="SELECT O.Pk_Objective_Id, O.Title, M.fk_Category_Id FROM dml_np_Objective AS O INNER JOIN dml_np_Objective_Category_Mapping AS M ON O.Pk_Objective_Id = M.fk_Objective_Id WHERE (M.fk_Category_Id = @CID) ORDER BY O.Pk_Objective_Id DESC">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="CatID" Name="CID" PropertyName="Text" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                    </div>
                </ItemTemplate>
            </asp:DataList>
        </div>
    </section>
    <div>
        <asp:SqlDataSource ID="SqlDataSourceCategory" runat="server" ConnectionString="<%$ ConnectionStrings:ConString %>" SelectCommand="SELECT [Pk_Category_Id], [Category_Title] FROM [dml_np_Category] WHERE ([Is_Active] = @Is_Active) ORDER BY [Pk_Category_Id] DESC">
            <SelectParameters>
                <asp:Parameter DefaultValue="true" Name="Is_Active" Type="Boolean" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>

    <script> <!--Script to add scrollbar to the category boxes-->
    $(function () {
        $('.catcontent').slimscroll({
            height: '180px',
            width: '100%',
            opacity: '.08',
            distance: '0px'
        }).parent().css({
            'float': 'left',
            'margin-right': '1px'
        });
    });
    </script>
</asp:Content>

推荐答案

(function () {
(function () {


('.catcontent').slimscroll({
height: '180px',
width: '100%',
opacity: '.08',
distance: '0px'
}).parent().css({
'float': 'left',
'margin-right': '1px'
});
});
</script>
('.catcontent').slimscroll({ height: '180px', width: '100%', opacity: '.08', distance: '0px' }).parent().css({ 'float': 'left', 'margin-right': '1px' }); }); </script>







I have tried all the possibilities, added both in the master page, added both in the content page adding ref in the master page and script in the content page! Since I have a very weak logic base of how a browser checks the script so unable to achieve what I want to!



This script is working fine if I make a separate aspx page. Adds a scrollbar neatly to the




I have tried all the possibilities, added both in the master page, added both in the content page adding ref in the master page and script in the content page! Since I have a very weak logic base of how a browser checks the script so unable to achieve what I want to!

This script is working fine if I make a separate aspx page. Adds a scrollbar neatly to the

<div>

. But it is not working when I’m trying to add it inside a content page!



Also when you answer this! Please try and explain me what is the best practice and how to actually add it!! I remember of adding css and js to content pages in the past! But I was a little out of touch and I tried searching in the internet! Nothing worked for me today! Please help me! Thanks



Master page:



. But it is not working when I'm trying to add it inside a content page!

Also when you answer this! Please try and explain me what is the best practice and how to actually add it!! I remember of adding css and js to content pages in the past! But I was a little out of touch and I tried searching in the internet! Nothing worked for me today! Please help me! Thanks

Master page:

<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
    <!--CSS Stylesheets-->
    <link rel="stylesheet" type="text/css" href="~/Content/css/bootstrap-theme.min.css" />
    <link rel="stylesheet" type="text/css" href="~/Content/css/bootstrap.min.css" />
    <link rel="stylesheet" media="screen" href="~/Content//font-awesome/css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="~/Content/css/style.css" />
    <!-- Javascript -->
    <script src="~/Scripts/js/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="~/Scripts/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="Scripts/js/jquery.slimscroll.min.js" type="text/javascript"></script>


</head>
<body>
    <form id="form1" runat="server">
        <div>
<div class="container">
<p>ldlajdlkdjljda</p>
</div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>
        </div>
    </form>
</body>
</html>







Content Page:






Content Page:

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

    <header>
        <div class="container">
        </div>
    </header>
    <section class="category">
        <div class="container">
            <h2>Some text goes here</h2>
            <p>
                Some text goes here...Some text goes here...Some text goes here...
                Some text goes here...Some text goes here...Some text goes here...
                Some text goes here...Some text goes here...Some text goes here...
                Some text goes here...Some text goes here...Some text goes here...
                Some text goes here...Some text goes here...Some text goes here...
            </p>
            <span class="row" />
        </div>
        <div class="container content">
            <asp:DataList ID="DataListCategory" runat="server" DataKeyField="Pk_Category_Id" DataSourceID="SqlDataSourceCategory" RepeatDirection="Horizontal" RepeatColumns="4" Width="100%" CssClass="row" AlternatingItemStyle-HorizontalAlign="NotSet" RepeatLayout="Flow">
                <ItemTemplate>
                    <div class="col-sm-12 col-md-3 item">
                        <asp:Label runat="server" ID="CatID" Text='<%# Eval("Pk_Category_Id") %>' Visible="False" />
                        <h4><%# Eval("Category_Title") %></h4>
                        <div class="catcontent">
                            <ul>
                                <asp:DataList ID="DataListObjectivesList" runat="server" DataKeyField="Pk_Objective_Id" DataSourceID="SqlDataSourceObjectives">
                                    <ItemTemplate>

                                        <li>
                                            <asp:HyperLink ID="linkObjective" runat="server" Target="_blank"

                                                Text='<%# Eval("Title") %>'

                                                NavigateUrl='<%# "Objective.aspx?oid=" + Eval("Pk_Objective_Id")%>' />
                                        </li>
                                    </ItemTemplate>
                                </asp:DataList>
                            </ul>
                        </div>
                    </div>
                    <div>
                        <asp:SqlDataSource ID="SqlDataSourceObjectives" runat="server" ConnectionString="<%


ConnectionStrings:ConString %>\" SelectCommand=\"SELECT O.Pk_Objective_Id, O.Title, M.fk_Category_Id FROM dml_np_Objective AS O INNER JOIN dml_np_Objective_Category_Mapping AS M ON O.Pk_Objective_Id = M.fk_Objective_Id WHERE (M.fk_Category_Id = @CID) ORDER BY O.Pk_Objective_Id DESC\">
<SelectParameters>
<asp:ControlParameter ControlID=\"CatID\" Name=\"CID\" PropertyName=\"Text\" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</ItemTemplate>
</asp:DataList>
</div>
</section>
<div>
<asp:SqlDataSource ID=\"SqlDataSourceCategory\" runat=\"server\" ConnectionString=\"<%
ConnectionStrings:ConString %>" SelectCommand="SELECT O.Pk_Objective_Id, O.Title, M.fk_Category_Id FROM dml_np_Objective AS O INNER JOIN dml_np_Objective_Category_Mapping AS M ON O.Pk_Objective_Id = M.fk_Objective_Id WHERE (M.fk_Category_Id = @CID) ORDER BY O.Pk_Objective_Id DESC"> <SelectParameters> <asp:ControlParameter ControlID="CatID" Name="CID" PropertyName="Text" /> </SelectParameters> </asp:SqlDataSource> </div> </ItemTemplate> </asp:DataList> </div> </section> <div> <asp:SqlDataSource ID="SqlDataSourceCategory" runat="server" ConnectionString="<%


这篇关于如何在asp.net的母版页的内容页面中包含jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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