ASP.Net:用户控件添加到动态占位符不能检索值 [英] ASP.Net: User controls added to placeholder dynamically cannot retrieve values

查看:107
本文介绍了ASP.Net:用户控件添加到动态占位符不能检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我动态添加一些用户控件的占位符服务器控件。我的用户控件包含一些标签和一些文本框控件。

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:


  • 初始化(Init事件)

  • 开始跟踪视图状态(检查回发)

    • 加载视图状态(如果回发)

    • 加载回发数据(如果回发)


    • 抬起变化事件(如果回发)

    • 提高回发事件(如果回发)

    正如你所看到的,ViewState的数据传回控件的加载Load事件发生之前。因此,为了您的动态添加控件保留的价值观,他们要的 present 的为ASP.NET页面,在第一时间重新加载值。你将不得不重新创建在初始化阶段的控制,前负荷视图状态发生。

    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:用户控件添加到动态占位符不能检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆