문제

I add the WebUserControl in runtime, so I can't use MyWebUserControl.MyFunction(), I have a MasterPage and I tried this:

_MainContentPage = CType(_Page.Form.FindControl("MyContentPlaceHolder"), ContentPlaceHolder)
CType(_MainContentPage.FindControl("MyWebUserControl"), myType)

But _MainContentPage.FindControl("MyWebUserControl") returns a TableCell.

The way I add the WubUserControl:

tcValue = New TableCell()      
tcValue.Controls.Add(_Page.LoadControl("Paht/WebUserControl"))
tcValue.ID = "MyWebUserControl"

Well thats cause _MainContentPage.FindControl("MyWebUserControl") returns a TableCell but how to get the Webcontrol and call the Function.

도움이 되었습니까?

해결책 2

The solution is get the TableCell and then find the control, after that call the function.

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

다른 팁

How difficult is to make that function as a web method or extract that function in a asp.net http handler to be accessed globally. I think this way you can make it better rather than using reflections and other things to access it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top