在ASP.net页面里取得用户控件里面的值

一.在用户控件里添加如下代码:

public event EventHandler gg;
  
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session["ccc"] = TextBox1.Text;
      
        if (gg != null)
        {

            gg(this, e);

        }


    }

二.在引用用户控件里的代码写入(记得要在用户控件里加入刚都声明的事件)

   如: <uc1:WebUserControl ID="WebUserControl1" runat="server" Ongg ="cc"/>

    protected void cc(object sender, EventArgs e)
    {
        if (Session["ccc"] != null)
        {
            TextBox1.Text = Session["ccc"].ToString();
            Session.Remove("ccc");
        }
    }


   本人博客的文章大部分来自网络转载,因为时间的关系,没有写明转载出处和作者。所以在些郑重的说明:文章只限交流,版权归作者。谢谢

原文地址:https://www.cnblogs.com/wzg0319/p/1398585.html