c# - Pass variables and access methods of User Control from CodeBehind -
so have function renderwidget() in default.aspx.cs. idea of add user control page.
public void renderwidget(string data) { control ctrl = page.loadcontrol("/widgets/widget.ascx"); datapanel.controls.add(ctrl); } this works fine, lovely jubbly. in other end, @ user control, have following code in widget.ascx.cs:
public class widgetcontrol : system.web.ui.usercontrol { public string teststring = ""; public void test() { response.write("test"); } } the problem arises when try access either of properties in user control. when try add ctrl.test() or ctrl.teststring = "test" default.aspx.cs, error "'system.web.ui.control' not contain definition 'test'". feel there's basic i'm missing here.
any appreciated, thanks!
you have cast correct type:
widgetcontrol widget = (widgetcontrol)ctrl; widget.teststring = "foo"; widget.test(); loadcontrol returns control , not actual type of usercontrol.
Comments
Post a Comment