简体   繁体   English

ASPX页面中的样式问题

[英]Styling issue in ASPX page

I have an ASPX page that is suppose to output 5 instances of one custom control (basically a table with data grabbed from a database). 我有一个ASPX页面,该页面假定输出一个自定义控件的5个实例(基本上是一个从数据库中获取数据的表)。 I am relatively new to ASP.NET as well as JavaScript, so I am having some difficulty fixing this styling issue. 我对ASP.NET和JavaScript相对较新,因此在解决此样式问题时遇到了一些困难。

My problem is that, styling on the custom control (the table) is only being applied to the first instance of the control. 我的问题是,自定义控件(表)上的样式仅应用于控件的第一个实例。 I am not sure why that is. 我不确定为什么会这样。 I have put my code up (I renamed a lot of things to keep this generic). 我已经编写了代码(为了保持通用性,我重命名了很多东西)。 How would I go about making the styling apply to all 5 instances? 如何将样式应用于所有5个实例?

<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXX" Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register TagPrefix="company" TagName="Control3" Src="~/Common/Controls/Control3.ascx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link type="text/css" rel="stylesheet" href="<%=ResolveUrl("~/Project/Css/Dashboard.css") %>" />
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <div id="dashboardContent">

        <div id="id1">

            <%-- ID1 --%>
            <div class="roundedTop">
                <asp:Label ID="lblID1" runat="server" CssClass="InputHeader" meta:resourcekey="lblID1" />
            </div>

            <div class="roundedMain"><!--<![endif]-->

                <company:Control3 ID="control3First" runat="server" meta:resourcekey="control3First"
                    Filter="" />
            </div>
        </div>

        <div id="id2">

            <%-- ID2 --%>
            <div class="roundedTop">
                <asp:Label ID="lblID2" runat="server" CssClass="InputHeader" meta:resourcekey="lblID2" />
            </div>

            <div class="roundedMain"><!--<![endif]-->

                <company:Control3 ID="control3Second" runat="server" meta:resourcekey="control3Second"
                    Filter="" />
            </div>
        </div>

        <div id="id3">

            <%-- ID3 --%>
            <div class="roundedTop">
                <asp:Label ID="lblID3" runat="server" CssClass="InputHeader" meta:resourcekey="lblID3" />
            </div>

            <div class="roundedMain"><!--<![endif]-->

                <company:Control3 ID="control3Third" runat="server" meta:resourcekey="control3Third"
                    Filter="" />
            </div>
        </div>

        <div id="id4">

            <%-- ID4 --%>
            <div class="roundedTop">
                <asp:Label ID="lblID4" runat="server" CssClass="InputHeader" meta:resourcekey="lblID4" />
            </div>

            <div class="roundedMain"><!--<![endif]-->

                <company:Control3 ID="control3Forth" runat="server" meta:resourcekey="control3Forth"
                    Filter="" />
            </div>
        </div>

        <div id="id5">

            <%-- ID5 --%>
            <div class="roundedTop">
                <asp:Label ID="lblID5" runat="server" CssClass="InputHeader" meta:resourcekey="lblID5" />
            </div>

            <div class="roundedMain"><!--<![endif]-->

                <company:Control3 ID="control3Fifth" runat="server" meta:resourcekey="control3Fifth"
                    Filter="" />
            </div>
        </div>

    </div>

    <asp:Timer ID="tUpdateTimer" runat="server" ontick="tUpdateTimer_Tick"></asp:Timer>

    <asp:UpdatePanel ID="upTimer" runat="server" UpdateMode="Conditional">
        <ContentTemplate />
        <Triggers><asp:AsyncPostBackTrigger ControlID="tUpdateTimer" EventName="Tick" /></Triggers>
    </asp:UpdatePanel>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="JavascriptContent" runat="server">

    <script type="text/javascript">

        var tblSomething = null;
        var tblHostConnection = null;

        function pageLoad(sender, args) {
            attachDataTablesToSomethingTable();
            attachDataTablesToHostConnectionTable();
        }

        function attachDataTablesToSomethingTable() {
            tblSomething = $('#tblSomething').dataTable({
                "bRetrieve": true,
                "bServerSide": false,
                "bPaginate": false,
                "bFilter": false,
                "bSort": false,
                "bJQueryUI": true,
                "sScrollY": "230px",
                "sScrollX": "100%",
                "oLanguage": {
                    "sEmptyTable": '<%= GetLocalResourceObject("tblSomething.Empty").ToString() %>',
                    "sProcessing": '<img id="imgAnim" src="<%= ResolveUrl(Resources.SiteIcons.Loader) %>" />',
                    "sInfo":
                                '<%= GetLocalResourceObject("sInfo.Showing").ToString() %>' + ' _START_ ' +
                                '<%= GetLocalResourceObject("sInfo.to").ToString() %>' + ' _END_ ' +
                                '<%= GetLocalResourceObject("sInfo.of").ToString() %>' + ' _TOTAL_ ' +
                                '<%= GetLocalResourceObject("sInfo.entries").ToString() %>'
                }
            });
        }

        function attachDataTablesToHostConnectionTable() {
            tblHostConnection = $('#tblHostConnection').dataTable({
                "bRetrieve": true,
                "bServerSide": false,
                "bPaginate": false,
                "bFilter": false,
                "bSort": false,
                "bJQueryUI": true,
                "sScrollY": "100%",
                "sScrollX": "100%",
                "oLanguage": {
                    "sEmptyTable": '<%= GetLocalResourceObject("tblHostConnection.Empty").ToString() %>',
                    "sProcessing": '<img id="imgAnim" src="<%= ResolveUrl(Resources.SiteIcons.Loader) %>" />',
                    "sInfo": ''
                }
            });
        }

    </script>

</asp:Content>

From a bit of playing around, if I commented out attachDataTablesToSomethingTable() from the JavaScript call at the bottom, then no styling was applied to any table, so I assume that is the function that applies/calls the styling. 从一点玩法来看,如果我从底部的JavaScript调用中注释掉attachDataTablesToSomethingTable() ,则没有样式应用于任何表,因此我假设这是应用/调用样式的函数。 Again, I am inexperienced with ASP.NET and JavaScript, so if anyone could shed any light, that would be awesome. 同样,我对ASP.NET和JavaScript经验不足,所以如果任何人都可以了解一下,那就太好了。

I'll agree with @lucuma's comment to your question. 我会同意@lucuma对您的问题的评论。 So, I may suggest you to implement unique id for table of each custom control instance. 因此,我建议您为每个自定义控件实例的表实现唯一的ID。 This can be achieved by implementing a public property say 'TableID' in your custom control, which can be configured for each custom control instance. 这可以通过在自定义控件中实现一个名为“ TableID”的公共属性来实现,可以为每个自定义控件实例进行配置。

The below parts go into user custom control implementation: 以下部分将介绍用户自定义控件的实现:

Code behind: 后面的代码:

public string TableID
{
   get;
   set;
}

Markup: 标记:

<table id='<%=TableID %>'>

Configure the TableID property for each custom control instance in aspx page: 为aspx页面中的每个自定义控件实例配置TableID属性:

<company:Control3 ID="control3First" runat="server" meta:resourcekey="control3First" Filter=""
TableID='mytable1' />

<company:Control3 ID="control3Second" runat="server" meta:resourcekey="control3Second" Filter=""
TableID='mytable2' />

And finally, wire up jquery plug-in for each table... 最后,为每个表连接jQuery插件...

mytable1 = $('#mytable1').dataTable(...);
mytable2 = $('#mytable2').dataTable(...);

Hope this helps... 希望这可以帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM