读书人

怎样向Web用户控件传参数?就象用URL传

发布时间: 2012-03-29 12:53:13 作者: rapoo

怎样向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 = ....

读书人网 >asp.net

热点推荐