.net UserControl用户控件传值

用户控件中设置属性

ascx.cs
 private string tableName;


    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(TableName);
       
    }


    public string TableName
    {
        get { return tableName; }
        set { tableName = value; }
    }

    public void getDB(string TableName)
    {
        tableName = TableName;
    }

 页面代码文件

.cs

public partial class PageCommon : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        //获得父页面
        //Page p = this.Parent.Page;
        //获得父页面的子控件
        UserControl uc = this.FindControl("WebUserPage1") as UserControl;

        WebUserPage1.TableName = "db";
    }
}

原文地址:https://www.cnblogs.com/meetweb/p/1490108.html