ASP.Net:动态添加到占位符的用户控件无法检索值

ASP.Net: User controls added to placeholder dynamically cannot retrieve values(ASP.Net:动态添加到占位符的用户控件无法检索值)
本文介绍了ASP.Net:动态添加到占位符的用户控件无法检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向 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:动态添加到占位符的用户控件无法检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)