我想加載 2 個(gè)用戶控件(相同但具有不同的文本屬性)。我的用戶控件包含一個(gè)標(biāo)簽,其中包含為 ascx.cs 中的文本定義的函數(shù)我正在使用面板在運(yùn)行時(shí)加載控件..在這里我希望用戶控件標(biāo)簽具有不同的文本。我的 .ascx 文件 <asp:Label ID="uclbl" runat="server" />我的 .ascx.cs 文件 public string textforlabel { get { return uclbl.Text; } set { uclbl.Text = value; } }我的 .aspx 文件 <asp:Panel ID="panelMain" runat="server" > </asp:Panel>* 我已經(jīng)注冊(cè)了控件我的 .aspx.cs 文件Control _dummyUserControl = (Control)Page.LoadControl("~/UserControl/User1.ascx"); _dummyUserControl. ; //can not find the textforlabel here panelMain.Controls.Add(_dummyUserControl);
2 回答

慕森卡
TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超8個(gè)贊
因?yàn)槟M(jìn)行了不正確的轉(zhuǎn)換,您應(yīng)該轉(zhuǎn)換為您的用戶控件類(lèi)型:
User1 _dummyUserControl = (User1)Page.LoadControl("~/UserControl/User1.ascx");
_dummyUserControl.MyProperty = "SDfsdf" ; //here you can find all your custom properties
panelMain.Controls.Add(_dummyUserControl);

HUWWW
TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊
你必須輸入強(qiáng)制轉(zhuǎn)換:
User1 _dummyUserControl = (User1)Page.LoadControl("~/UserControl/User1.ascx");
- 2 回答
- 0 關(guān)注
- 189 瀏覽
添加回答
舉報(bào)
0/150
提交
取消