动态加载用户控件传参

来源:互联网 发布:光盘重装ubuntu系统 编辑:程序博客网 时间:2024/06/04 09:26

一:直接给控件赋值

System.Web.UI.UserControl myControl = (System.Web.UI.UserControl)LoadControl("include/" + linkAddress + "pic.ascx");        myControl.ID = "picuc1";//寻找控件中的标签使用        PlaceHolder1.Controls.Add(myControl);        begintime = DateTime.Parse(begintime).ToString("MM月dd日");        endtime = DateTime.Parse(endtime).ToString("MM月dd日");        ((Label)PlaceHolder1.FindControl("picuc1").FindControl("l_count")).Text = Total;        ((Label)PlaceHolder1.FindControl("picuc1").FindControl("l_time")).Text = begintime + "-" + endtime; ;        ((Label)PlaceHolder1.FindControl("picuc1").FindControl("l_tel")).Text = phone;

二:通过传参数

aspx.csSystem.Web.UI.UserControl myControl = (System.Web.UI.UserControl)LoadControl("include/" + linkAddress + "pic.ascx");        myControl.GetType().GetProperty("typeid").SetValue(myControl, typeid, null); //给控件传typeid        PlaceHolder1.Controls.Add(myControl);ascx.cspublic int _typeid = 0;    public int typeid    {        get        {            return _typeid;        }        set        {            _typeid = value;        }    }


原创粉丝点击