问题描述
我正在向 PlaceHolder 服务器控件动态添加一些用户控件.我的用户控件由一些标签和一些文本框控件组成.
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.
回发完成后,文本框会包含我在回发之前输入的数据.这告诉我,框中的文本正在通过 ViewState 保留.我只是不知道为什么我在调试时找不到它们.
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?
感谢您的帮助.
推荐答案
这是基于 .NET v1 的事件序列,但它应该给你的想法:
This is based on .NET v1 event sequence, but it should give you the idea:
- 初始化(初始化事件)
- 开始跟踪视图状态(检查是否回发)
- 加载视图状态(如果回发)
- 加载回发数据(如果回发)
- 引发更改的事件(如果回发)
- 引发回发事件(如果回发)
如您所见,将 ViewState 数据加载回控件发生在 Load 事件之前.因此,为了让您动态添加的控件保留"这些值,它们必须存在,以便 ASP.NET 页面首先重新加载这些值.在加载视图状态发生之前,您必须在 Init 阶段重新创建这些控件.
As you can see, the loading of ViewState data back to the controls happen before the Load event. So in order for your dynamically-added controls to "retain" those values, they have to be present for the ASP.NET page to reload the values in the first place. You would have to re-create those controls at the Init stage, before Load View State occurs.
这篇关于ASP.Net:动态添加到占位符的用户控件无法检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!