如何检索回发动态创建控件的子控件的值? [英] How to Retrieve Values of A Dynamically Created Control's Child Controls on PostBack?

查看:116
本文介绍了如何检索回发动态创建控件的子控件的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑:我在aspx页面的标记的自定义服务器控件。这种控制在创建子控件的CreateChildControls()方法(例如,它检索数据库中的内容和基于内容的动态创建是的CheckBoxList 单选按钮列表

Given: I have a custom server control in the markup of an aspx page. This control creates child controls in its CreateChildControls() method (e.g. it retrieves content from a database and based on that content dynamically creates either a CheckBoxList or a RadioButtonList)

现在我明白,我不能访问回发动态创建的控件,除非我再补充他们在Page_Init或Page_ preINIT(按<一个href=\"http://stackoverflow.com/questions/3019760/access-values-of-controls-dynamically-created-on-postback\">here).

Now I understand that I cannot access the dynamically created controls on postback unless I add them again on Page_Init or Page_PreInit (as per here).

我的问题是,如何我明确在Page_Init或Page_ preINIT再次添加他们,如果他们只是将要再次添加时,我们避开调用渲染() 在每个自定义服务器控件的?

My question is, how do I add them again explicitly in Page_Init or Page_PreInit if they are just going to be added yet again when we get around to calling Render() on each of the custom server controls?

我非常肯定这不是一个独特的问题,所以必须有这样做的最佳实践方法......我只是不知道它是什么:/

I'm very certain this is not a unique problem, so there must be a best practice way of doing it...I just don't know what it is :/

推荐答案

所有你需要做的就是创建你在pre_Init自定义服务器控件。其他一切为您处理。我想你想得好好的,这是怎么回事,它的混乱:)

All you need to do is create you Custom server control in the Pre_Init. Everything else is handled for you. I think you're thinking too hard about what is going on and it's confusing :)

自定义控制将呈现的子控件,而在pre_Init事件。他们将不会被渲染两次。

The custom control will render the child controls while in the Pre_Init event. They won't get rendered twice.

这篇关于如何检索回发动态创建控件的子控件的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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