0

我在运行时添加了 WebUserControl,所以我不能使用MyWebUserControl.MyFunction(),我有一个 MasterPage,我试过这个:

_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 的原因,但是如何获取 Webcontrol 并调用函数。

4

2 回答 2

0

将该函数作为 Web 方法或在 asp.net http 处理程序中提取该函数以供全局访问是多么困难。我认为通过这种方式你可以让它变得更好,而不是使用反射和其他东西来访问它。

于 2013-04-05T18:34:32.863 回答
0

解决方案是获取 TableCell 然后找到控件,然后调用该函数。

_MainContentPage = CType(_Page.Form.FindControl("MyContentPlaceHolder"),ContentPlaceHolder)
MyTableCell =  CType(_MainContentPage.FindControl("MyWebUserControl"), TableCell)
MyWebControl = CType(MyTableCell.Controls(0), MyType)
MyWebControl.MyFunction()
于 2013-04-09T15:00:26.253 回答