send custom parameters to user control ascx(将自定义参数发送到用户控件 ascx)
问题描述
我需要在页面上使用用户控件 (.ascx),它是基于 2 个参数的相关帖子用户控件:
I need to use user controls (.ascx) on a page, it's a related post user control based in 2 parameters:
1. Current post
2. Relation type
页面需要有 3 个不同的此控件实例,每个实例具有相同的 Current post 参数,但关系类型不同(标题、作者、流派).
the page needs to have 3 different instances of this control, each having the same Current post parameter, but different relation type (title, author, genre).
第一个参数我可以通过url获取,但是第二个参数呢?
The 1st parameter I can get it through url, but what about the second parameter?
我已经在谷歌上搜索了一段时间,但我还没有找到答案.如何传递第二个参数,以便控件可以根据这些参数加载信息?我宁愿不为每个参数创建一个控件,否则最好不构建用户控件而是直接进入代码:(谢谢!
I've been googling for a while but i haven't found an answer yet. How can I pass the second parameter so the control can load the information based on these parameters? I'd rather not to create a control for each parameter, else would be better to build no user control but direct into code :( Thanks!
推荐答案
创建用户控件的公共属性,如:
Create public properties of the user-control like:
public partial class SampleUC : UserControl
{
public string CurrentPost {get;set;}
public string RelationType {get;set;}
//...
//...
}
使用标记从页面中分配那些,例如:
Assign those from the page using it either from markup like:
<%@ Register TagPrefix="cc" TagName="SampleUC" Src="SampleUC.ascx" %>
...
...
<cc:SampleUC id="myUC" runat="server" CurrentPost="Sample Post Title" RelationType="Title" />
或来自(使用它的页面的)代码隐藏:
or from code-behind (of the page using it):
protected void Page_Load(object sender, EventArgs e)
{
//...
myUC.CurrentPost = "Sample Post Title";
myUC.RelationType = "Title" ;
//...
}
这篇关于将自定义参数发送到用户控件 ascx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将自定义参数发送到用户控件 ascx


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01