方法1;
在自定义控件里声明一个全局变量如;public string parentID="";
在test.aspx里声明控件时同时赋值如
<uc1:webUserControl1 id="MyControl1" runat="server" parentID=“XXX”></uc1:MyControl>
方法2:
在test.aspx.cs中
webUserControl innerControl= (webUserControl)e.Item.FindControl("MyControl1");
innerControl.test = "XXXXXX";
在自定义控件里
private string _test;
public string test
{
get
{
return _test;
}
set
{
_test = value;
}
}
本文介绍两种在ASP.NET中实现自定义控件传值的方法:一种是在自定义控件中声明全局变量并通过在页面中声明控件时直接赋值;另一种是在页面后端代码中通过FindControl方法找到自定义控件并设置其属性。

753

被折叠的 条评论
为什么被折叠?



