日期:2014-05-18  浏览次数:20436 次

动态添加自定义控件如何传参数?
C# code

Control MUser = Page.LoadControl("Controls/Muser.ascx");
PanelMUser.Controls.Add(MUser);



上面这个代码是动态添加自定义控件的代码,那么怎样才能给这个自定义控件传个参数呢?因为我的自定义控件里根据这个参数的不同现实的内容也不同的。
谢谢大家。

------解决方案--------------------
使用生名用户控件类的方式可以解决

代码如下:

---------------------------------------------
UserControls.GoodLessonMore2 objGoodLessonMore = new UserControls.GoodLessonMore2();

//设置属性
objGoodLessonMore.SkinFilename = "Theme" + GetTemplateID() + "/Masters/GoodLessonMore2.ascx";
phContainer.Controls.Add(objGoodLessonMore);

------------------------------------------
 <form id="form1" runat="server">
<asp:PlaceHolder ID="phContainer" runat="server"></asp:PlaceHolder>
</form>


public class GoodLessonMore2 : WebControl, INamingContainer