ASP.Net: User controls added to placeholder dynamically cannot retrieve values

前端 未结 8 1762
攒了一身酷
攒了一身酷 2021-02-09 02:53

I am adding some user controls dynamically to a PlaceHolder server control. My user control consists of some labels and some textbox controls.

When I submit the form

8条回答
  •  日久生厌
    2021-02-09 03:55

    Ensure you are defining your dynamic controls at the class level and adding them to the ASP container:

    Private dynControl As ASP.MyNamespace_MyControl_ascx
    

    And when you instantiate the control, ensure you call LoadControl so the object is added properly:

    dynControl = CType(LoadControl("~/MyNamespace/MyControl/MyControl.ascx"), ASP.MyNamespace_MyControl_ascx)
    

提交回复
热议问题