首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎样向Web用户控件传参数?就象用URL传参数那样解决办法

2012-03-29 
怎样向Web用户控件传参数?就象用URL传参数那样URL传参数我通过Page.Response.Redirect( mypage.aspx &?

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

热点排行