T0:bryanscn 学长。
小弟现在遇到一个问题跟你在04年时的一个提问类似。。不知道你当时是怎么解决的?我现在急想知道这个答案。。
不知道能否得到你的提示。。谢谢了。
我的QQ:277648148问题如下:如何将外部参数传入ascx控件内?
我自己做了个控件add.ascx   
    
  在page里这样使用:   
  System.Web.UI.UserControl   _innerControl;   
    
  ...   
    
  {   
        ....   
        int   a   =   3;   
        _innerControl.LoadControl("/bin/add.ascx");   
        ....   
  }   
    
  现在我想把参数a的值输入控件add.ascx中,其中add.ascx的代码是写在page前台的,即写<script   language=c#   runat=server>...   ...</script>的   
    
  请问应该怎么传进去呢?   
    
  我试过Session   ,ViewState,   Application好像都不行,加?par=3也不行   
    
  清大虾指教!!   
    
  ps:我这么做是为了在sps 2007中的web   part能够引用这个控件,也就是把web   part的参数传入其中。   
    
  
如果有哪位朋友知道这个解答的。可否也帮小弟下。。谢谢。。

解决方案 »

  1.   

    我是写在webpart中。
    在MOSS 2007中。get{}set{} 只能写在webpart中才能在属性栏中才能显示出来。但我现在想要在ascx中得到这个值。。所以不知道要怎么作到。。
      

  2.   

    1。
    再次发现自己的理解能力如此之低2。
    在你的 ascx 中定义一个属性// add.ascx
    <script language=c# runat=server>
    public int MyPropertyA

        get {  
            object o = ViewState["MyPropertyA"]; 
            return (o == null) ? 0 : (int)o;
        }
        set { ViewState["MyPropertyA"] = value; }
    }
    </script>// 使用
    int a = 3;
    MyUserControl uc = _innerControl.LoadControl("/bin/add.ascx") as MyUserControl;  // 假设你的 用户控件名为 MyUserControl
    uc.MyPropertyA = 3;
    Response.Write(uc.MyPropertyA);
      

  3.   

    您的这个是在页面中取得ascx中的属性值..而我想要的是...把一个值从.cs中传到ascx中....========================难道我这不是从 cs 给 ascx 传值吗?uc.MyPropertyA = 3;
    [email protected]
    [email protected]
      

  4.   

    貌似极其简单的问题...不过我不是你的bryanscn 学长....不抢别人风头了...
      

  5.   

    是啊.应该是蛮简单的.不知道你能帮我吗?
    我现在有两个文件.一个是STMenuBlock.cs (webpart文件).在这里面有这么一句代码
     Control _innerUserControl = new Control();
     _innerUserControl = this.Page.LoadControl("/bin/STMenuBlock.ascx");
     this.Controls.Add(_innerUserControl);假设在这个.cs文件中.要传这么一个值给STMenuBlock.ascx,要怎么传.(用户控件是接收方)
      

  6.   

    在用户控件里添加一个公有属性,然后再页面的cs文件里用
    (this.FindControl(控件id) as 控件类).公有属性 应该就可以传值了