电竞比分网-中国电竞赛事及体育赛事平台

分享

掉掉注意了,如何動態(tài)加載用戶控件(ascx)

 素行 2007-03-15
注: 本方法是我同事李強原創(chuàng)

步驟一: 把ascx控件拖入設計窗口,然后轉入html模式,保留定義
如果你需要多個ascx的話,請全部拖入。
但是把相應的內(nèi)容刪除。(因為我們需要動態(tài)加載)
在需要填入控件的地方,放個容器,比如td,并設定在服務器端運行

    <TD  id="tdpan" runat=server></TD>

2:動態(tài)調用
UserControl myusercontrol = (UserControl) LoadControl ("../includes/pageNavigater.ascx") ;
            Type myusertype = myusercontrol.GetType();
//下面是給ascx賦值
            PropertyInfo  myuserinfo1 = myusertype.GetProperty("RelatedDatagrid");//) .GetProperty("RelatedDatagrid");
            myuserinfo1.SetValue(myusercontrol,gridhwcy  ,null);

            
            PropertyInfo  mypassinfo = myusertype.GetProperty("torefresh");
            mypassinfo.SetValue(myusercontrol,true,null );
            
            PropertyInfo  myuserdatasource = myusertype.GetProperty("RelatedDataSource");
            myuserdatasource.SetValue(myusercontrol,dv,null);

            tdpan.Controls.Clear();
            tdpan.Controls.Add(myusercontrol);

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多