在页面中,申明一个保护型的变量,名称同html中的控件id
然后可以在codebehind中引用它的属性

解决方案 »

  1.   

    if you use codebehind, then your life is much easier, you can cast the control to your codebehind class and retrieve the property, for now, you have to do1. test.ascx:
    <%@ Control Language="VB"%>
    <script runat="server"> 
      private _a as string = "hello"
       
      Public property a() as string 
        get 
         return _a 
       end get 
       set (ByVal value as String)
         _a=value 
       end set 
      end property 
       
      sub page_load(obj as object,e as eventargs) 
        _a="mrhgw" 
        'Page.Response.Write (_a)
      end sub 
    </script> 
    2. test.aspx:
    <%@ Register TagPrefix="tt" TagName="Hello" src="test.ascx" %>
    <tt:Hello id="hello" runat="Server" />
    <script language="C#" runat="server">
    void Page_PreRender(Object o, EventArgs e)
    {
      Type t  = hello.GetType();   
      System.Reflection.PropertyInfo pi = t.GetProperty("a");
      Response.Write( pi.GetValue(hello,null));
    }
    </script>
      

  2.   

    in your aspx's code behind, declareprotected UserControl hello;