我添加了WebUserControl在運行,所以我不能使用MyWebUserControl.MyFunction()
,我有一個母版和我想這一個:如何調用ASPX頁面上的ASCX頁面功能?
_MainContentPage = CType(_Page.Form.FindControl("MyContentPlaceHolder"), ContentPlaceHolder)
CType(_MainContentPage.FindControl("MyWebUserControl"), myType)
但_MainContentPage.FindControl("MyWebUserControl")
返回一個TableCell的。
我的方式添加WubUserControl:
tcValue = New TableCell()
tcValue.Controls.Add(_Page.LoadControl("Paht/WebUserControl"))
tcValue.ID = "MyWebUserControl"
那麼這就是原因_MainContentPage.FindControl("MyWebUserControl")
返回TableCell的 但如何讓Web控件,並調用Fcuntion。
您可能必須使用反射來探測用戶控件類,然後調用該方法。 – AlwaysAProgrammer 2013-04-05 18:00:02
謝謝,但我已經做到了(請參閱問題更新) – Logar314159 2013-04-05 18:27:23
假設您的ascx位於佔位符中,您是否可以遍歷佔位符中的控件並執行類似'If(TypeOf(control)is MyAscx')然後DirectCast控制,MyAscx).MyMethod()'? – valverij 2013-04-05 18:40:11