- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 ASP.NET 的新手,但一直在顺利进行,通过一些研究能够克服迄今为止的所有障碍。但是我遇到了一个似乎无法解决的小问题,涉及我创建的自定义控件。
该控件是一个通过 JQuery 弹出的小部件,包含允许用户过滤结果集的控件。我将此弹出窗口的所有元素嵌入到两个特定页面中,并且这些页面都运行良好。我决定创建一个自定义控件,并且据我所知已经正确地完成了,在目标页面上使用带有 Control' 指令和
Register' 指令的 ascx 文件,所以:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PopUp_TopicFilterControl.ascx.cs" Inherits="POD.PopUp_TopicFilterControl" %>
和
<%@ Register TagPrefix="popup" TagName="TopicFilterControl" Src="~/Controls/PopUp_TopicFilterControl.ascx" %>
“主”页面包含一个对象数据源,它需要在我的自定义控件中引用控件以获取其选择参数。这是数据源:
<asp:ObjectDataSource ID="TopicDataSource" runat="server" SelectMethod="GetRecentTopics" TypeName="POD.App_Objects.Topic">
<SelectParameters>
<asp:Parameter DefaultValue="12" Name="select_limit" Type="Int32" />
<asp:ControlParameter DefaultValue="" ControlID="TopicCategoryFilterList" Name="category" Type="String" />
<asp:ControlParameter DefaultValue="" ControlID="TopicCreatorFilterList" Name="creator" Type="Int32" />
<asp:ControlParameter DefaultValue="" ControlID="TopicDateAfterFilterText" Name="date_after" Type="String" />
<asp:ControlParameter DefaultValue="" ControlID="TopicDateBeforeFilterText" Name="date_before" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
这是自定义控件的主体:
<asp:Panel id="TopicFilter_Panel" runat="server" CssClass="PopUp" ClientIDMode="Static" EnableTheming="False" EnableViewState="False" ViewStateMode="Disabled">
<asp:Panel runat="server" CssClass="PopUp_Heading">
<h1><a id="TopicFilter_Close" href="#">Close [X]</a></h1>
</asp:Panel>
<asp:Panel runat="server" CssClass="PopUp_Body">
<asp:Table runat="server">
<asp:TableRow runat="server">
<asp:TableCell runat="server" HorizontalAlign="Right">
By Category:
</asp:TableCell>
<asp:TableCell runat="server">
<asp:DropDownList
ID="TopicCategoryFilterList"
runat="server"
DataSourceID="TopicCategoryDataSource"
DataTextField="value"
DataValueField="value"
AppendDataBoundItems="True"
AutoPostBack="False">
<asp:ListItem Selected="True" Value="">— All —</asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server" HorizontalAlign="Right">
By Author:
</asp:TableCell>
<asp:TableCell runat="server">
<asp:DropDownList
ID="TopicCreatorFilterList"
runat="server"
DataSourceID="UserDataSource"
DataTextField="person_name_full"
DataValueField="user_id"
AppendDataBoundItems="True"
AutoPostBack="False">
<asp:ListItem Selected="True" Value="">— All —</asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server" HorizontalAlign="Right">
By Date (After):
</asp:TableCell>
<asp:TableCell runat="server">
<asp:TextBox ID="TopicDateAfterFilterText" runat="server" />
<ajaxToolkit:CalendarExtender ID="TopicDateAfterCalendarExtender" TargetControlID="TopicDateAfterFilterText" PopupPosition="BottomRight" runat="server" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server" HorizontalAlign="Right">
By Date (Before):
</asp:TableCell>
<asp:TableCell runat="server">
<asp:TextBox ID="TopicDateBeforeFilterText" runat="server" />
<ajaxToolkit:CalendarExtender ID="TopicDateBeforeCalendarExtender" TargetControlID="TopicDateBeforeFilterText" PopupPosition="BottomRight" runat="server" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2" VerticalAlign="Bottom" HorizontalAlign="Center">
<asp:Button runat="server" Text="Apply" CssClass="PopUp_Apply" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:Panel>
</asp:Panel>
我得到的错误只是对象数据源没有看到我的自定义控件内的控件(例如,“在 ControlParameter 'category' 中找不到控件 'TopicCategoryFilterList'”)。显然这是一件非常简单的事情,但我似乎无法为我的生活简单地弄清楚如何使这项工作。我很确定这里一定已经解决了这个问题,但我找不到示例。
最佳答案
这是我自己对这个“问题”的解决方案,以防有人遇到同样的困难并像我一样疯狂地转动轮子来寻找答案。首先,这是返回自定义控件属性的代码片段。我将这段代码放在 ascx.cs 文件中:
public partial class PopUp_TopicFilterControl : System.Web.UI.UserControl
{
public string TopicCategory
{
get { return TopicCategoryFilterList.SelectedValue.ToString(); }
}
}
这里是对 ObjectDataSource 中的 ControlParameter 的更改:
<asp:ControlParameter
DefaultValue=""
ControlID="TopicFilterSelection"
PropertyName="TopicCategory"
Name="category"
Type="String" />
请注意,我所要做的就是将 ControlID 更改为我的自定义控件的名称,并添加 PropertyName 属性,该属性指的是我在 ascx.cs 文件中定义的属性。
这就是它的全部。当您看到它时很明显,但它让我难住了好几个小时。
关于c# - ControlParameter 找不到 UserControl 中的控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10017948/
我正在尝试在 Windows 上运行的小于 1GB 的 VM 上设置 YouTrack 和 TeamCity。使用率将非常低(用户和请求)。这是一个 POC 环境,如果它有效,我可能会将它推送到一个超
所以我在尝试使用 FORFILES 解决这个问题时遇到了麻烦。我正在尝试获取不超过 4 天的文件。所以基本上少于 4 天。然而,这似乎不太可能,因为/d -4 获取所有 4 天或更早的项目。 以下是我
如何从下面的 events 表中选择小于 15 分钟前创建的 events? CREATE TABLE events ( created_at timestamp NOT NULL DEFAU
Google Analytics Realtime提供 rt:minutesAgo ,可以过滤查询。 然而,它是一个维度而不是一个度量标准,<=不能在过滤器中使用。 假设我想在最后 n 分钟内获得一些
iOS 核心数据 - 严重的应用程序错误 - 尝试插入 nil 你好, 我的应用程序实际上运行稳定,但在极少数情况下它会崩溃并显示此错误消息... 2019-04-02 20:48:52.437172
我想制作一个 html div 以快速向右移动(例如不到 1 秒)并消失。然后1秒后再次直接出现在这个过程最开始div的位置。此过程将由单击按钮并重复 10 次触发。 我试图在 CSS 中使用过渡属性
我发现使用 TimeTrigger 是 Windows 10 (UWP) 上计划后台任务的方式。但是看起来我们需要给出的最小数字是 15 分钟。只是想知道,即使我们安排它在接下来的 1 分钟内运行,警
我必须在 1 秒内在屏幕上打印 2^20 行整数 printf 不够快,还有其他易于使用的快速输出替代方法吗? 每一行只包含 1 个整数。 我要求它用于竞争性编程问题,我必须将其源代码提交给法官。 最
我是一名优秀的程序员,十分优秀!