如何在ASPX页面上调用ASCX page函数



我在运行时添加了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并调用函数

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

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

_MainContentPage = CType(_Page.Form.FindControl("MyContentPlaceHolder"),ContentPlaceHolder)
MyTableCell =  CType(_MainContentPage.FindControl("MyWebUserControl"), TableCell)
MyWebControl = CType(MyTableCell.Controls(0), MyType)
MyWebControl.MyFunction()

最新更新