动态查找控件 [英] Dynamically Find Control

查看:62
本文介绍了动态查找控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




无法理解这一个!


我已逐渐命名为PlaceHolders,我想动态将控件加载到每个控件中。如果我强烈输入持有人姓名,一切都很好。但是如何动态引用持有者名称。


这就是我所拥有的;

Hi,

Can''t get my head round this one!

I have incrementally named PlaceHolders and I want to dynamically load a control into each one. All fine if I strongly type the holder name. But how do I reference the holder name dynamically.

Here''s what I have;

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号

推荐答案

这有用吗?


.FindControl()默认只检查中级孩子。

所以,例如,如果你有一个表单,其中有一个groupbox,然后在该组框中有2个文本框:

myForm

mygroupbox

mytextbox1

mytextbox2


做myForm.FindControl(" mytextbox1");不会工作,你需要做

mygroupbox.FindControl(" mytextbox1");让它返回obbject。


现在,.FindControl()被重载以获取第二个参数,该参数将告诉它搜索它的子节点的子节点,所以用它第二个参数你可以在myForm中搜索mytextbox1并让它工作。
Does that work?

.FindControl() only checks imediate children by default.
So for example, if you have a form, with a groupbox in it and then have 2 textboxes inside that groupbox:
myForm
mygroupbox
mytextbox1
mytextbox2

doing myForm.FindControl("mytextbox1"); will not work, you would need to do
mygroupbox.FindControl("mytextbox1"); to have it return the obbject.

Now, .FindControl() is overloaded to take a second parameter that will tell it to search the children of it''s children, so with that 2nd parameter you could search in myForm for mytextbox1 and have it work.


嗨Plater,


感谢您的回复!


不,它不起作用。 Findcontrol是错误的电话。我会进一步解释。


我想动态地给我的占位符控制列表。占位符id是PlaceHolder1,PlaceHolder2 ......等等。因此,我可以遍历数据库结果并根据结果将用户控件添加到占位符。我通常编写客户端Javascript / Actionscript脚本,并且不能取消和如何动态设置/获取PlaceHolder ID以便我可以添加控件。


任何想法?


真的很挣扎。
Hi Plater,

Thanks for your reply!

No it''s not working. Findcontrol is the wrong call. I''ll explain further.

I want to a list of control dynamically to my placeholders. The placeholder id''s are PlaceHolder1, PlaceHolder2 ... etc. So I can loop through database results and add User Controls to the placeholders depending on the results. I usually script client-side Javascript/Actionscript and can''t undertsand how to dynamically set/get the PlaceHolder id so I can add the control.

Any ideas?

Really struggling with this.


所以你想在客户端而不是在后端代码中做这个吗?
So you want to do this clientside and not in the backend code?


这篇关于动态查找控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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