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

怎样向Web用户控件传参数?就象用URL传参数那样
URL传参数我通过
Page.Response.Redirect( "mypage.aspx "   &   "?id=1 ")

但用户控件的装入不是通过Redirect,而是
Dim   UC   As   UserControl   =   CType(LoadControl( "mypage.ascx "),   UserControl)
Page1.Controls.Add(UC_User)

这一过程中类似id=1这样的参数该怎么传?(Application、Session等方法免谈)

------解决方案--------------------
呵呵,只是提醒你,“Dim UC As UserControl”这个类型不够具体。你应该把UC定义为具体的、具有具体属性接口的类型。
------解决方案--------------------
直接付给你的用户控件的属性

Dim UC As MyUserControlClass = CType(LoadControl( "mypage.ascx "), MyUserControlClass)
Page1.Controls.Add(UC)
UC.MyUserControlProperty1 = .... // MyUserControlClass 中定义了属性 MyUserControlProperty1

UC.MyUserControlProperty2 = ....