ASP.Net: User controls added to placeholder dynami

2019-03-20 07:11发布

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 and try to view the contents of the textboxes (within each user control) on the server, they are empty.

When the postback completes, the textboxes have the data that I entered prior to postback. This tells me that the text in the boxes are being retained through ViewState. I just don't know why I can't find them when I'm debugging.

Can someone please tell me why I would not be seeing the data the user entered on the server?

Thanks for any help.

8条回答
Root(大扎)
2楼-- · 2019-03-20 07:57

I also want to add that I've seen user controls work the way that you'd expect them to just by setting the Control.ID property at run time. If you do not set the ID, items may get built in a different order and work oddly.

查看更多
手持菜刀,她持情操
3楼-- · 2019-03-20 07:58

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)
查看更多
登录 后发表回答