供大家参考
“我在用户控件中有一个公用的属性和公用的方法,在调用他的页面中可以访问,但是在后置代码文件中确无法访问到这个用户控件。”
http://expert.csdn.net/Expert/topic/1989/1989975.xml?temp=.6281244

解决方案 »

  1.   

    这个别人不都有写的么,定义一下不就可以了?
    protected YouUserControlClass control1;
      

  2.   

    crodling(蓝风) ( ) 说得对
      

  3.   

    >>>1、如何在后台代码中设置和获取用户控件中的子控件的属性?add public properties/methods in your codebehind class for your usercontrol and declare in your page class:protected YourUserControlCodeBehindClass YourUserControlID;..if you don't have a  codebehind class, you can always doUserControl c = (UserControl)FindControl("YourUserControlID");TextBox tb = (TextBox) c.FindControl("YourTextBoxIDInYourUserControl);
    tb.Text = "123";>>>2、如何在后台设置和获取用户控件本身的属性?if you have a codebehind class for your usercontrol, you can do
    protected YourUserControlCodeBehindClass YourUserControlID;YourUserControlID.Property1 = "123";otherwise, you have to use Reflection
      

  4.   

    谢谢 saucer(思归) 
    我试了一下,你的方法可以。此问题基本得到了解决。
    菜鸟还有些疑问,Usercontrol的功能是不是有些太有限了一点?与内嵌组件相比,无论属性还是方法似乎都不够强大 -_-
      

  5.   

    顾名思义,UserControl是以界面为主的,但你可以在你的UserControl加属性/方法/事件,因为本质上,UserControl也是一个类而已UserControl的缺陷在于设计时的支持差,不能共享于不同项目,但它简单,易设计/修改,对技术人员的要求也不高