发送自定义参数的用户控件ASCX [英] send custom parameters to user control 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个不同的实例,每个具有相同的电流后的参数,但不同的关系类型(标题,作者,流派)。
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).
第1个参数,我可以得到它通过URL,但对于第二个参数?
The 1st parameter I can get it through url, but what about the second parameter?
我一直在Google上搜寻了一段时间,但我还没有找到答案。如何传递的第二个参数,以便控制可以加载基于这些参数的信息?
我宁愿不要为每个参数的控制,否则将是更好的建立没有用户的控制,但直接到code :(
谢谢!
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" />
或code-背后(页面使用它):
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!