2010-04-08 60 views
0

我想访问我的类文件中的用户控件而不是aspx.cs.i需要使用ASP.usercontrol_ascx类型对它进行类型转换,但我无法从我的.cs文件访问ASP名称空间..如何改变用户控件?访问asp.net中的类文件中的用户控件

日Thnx ....

回答

0

每个用户控制是从 UserControl类继承。

因此,有可能访问你的用户控件这样

UserControl userControl = (UserControl) new MyBrandUserControl(); 

做到这一点

在你要这种情况下,扩大层次。你所要做的就是创建一个类MyUserControlBase,它将继承UserControl类,并且你的MyBrandUserControl用户控件将继承MyUserControlBase类。

现在,你的财产将驻留在MyUserControlBase,你可以投它想:

MyUserControlBaseuserControl = (MyUserControlBase) new MyBrandUserControl(); 

请让我知道,如果你是不是在找这个。

+0

我已将公共属性添加到用户控件,所以我需要特定控件typecasted来访问这些属性。 – komal 2010-04-08 09:15:38

+0

我编辑了我的答案,请检查! – 2010-04-08 10:18:45