我试了在用户控件设置一个公共属性,在页面上也赋好了属性的值(页面文本框的值)
---------------------------
你是在什么地方赋值的?页面的Page_Load事件里?还是事件处理函数里?

解决方案 »

  1.   

    用 Session 方法传送接收
      

  2.   

    原因是这样的:
    含有用户控件的一般页面的处理顺序:1.页面的Page_Load函数 -〉2.用户控件的Page_Load函数 -〉3.用户控件的事件 -〉4.页面的事件。
    你是在第4步中赋值的,已经晚了。
      

  3.   

    Session["test"]= "test"
    if(Session["test"]!=null)
    {
       string test = Session["test"].ToString();
    }
      

  4.   

    是用Server.Transfer方法传值: public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.TextBox TextBox2;
    protected System.Web.UI.WebControls.Button Button1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } public string Text1 {
    get{ return this.TextBox1.Text; }
    } public string Text2 {
    get{ return this.TextBox2.Text; }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    Server.Transfer("WebForm2.aspx");
    } public class WebForm2 : System.Web.UI.Page
    {
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    WebForm1 wf1;
    wf1 = (WebForm1)Context.Handler; Response.Write(wf1.Text1 + wf1.Text2);
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load);
    }
    #endregion
    }
      

  5.   

    假设你有个<input type=text id=mytext name=mytext>
    并且你的那段文字是写在一个诸如<div>的区块中的,那么你可以这样赋值
    用JAVASCRIPT:
    window.form1.mytext.value=yourdiv.innerText;