Frage

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.

War es hilfreich?

Lösung 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()

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top