如何在代码背后获取用户控件 [英] How to get usercontrol controls in code behind

查看:84
本文介绍了如何在代码背后获取用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在usercontrol中有一个表单,当用户单击添加更多选项"时,会在运行时添加此控件.

在产品部分中,用户输入产品详细信息,但是当他们需要输入更多产品功能时,则需要单击添加更多选项",然后单击添加更多选项",将用户控制表单添加到页面中.但是在输入数据后,当我尝试从控件中获取虚标时得到空错误.我可以在后面的aspx代码中获取ascx用户控件的值.

如果有任何想法请回覆.

谢谢
Rajesh

Hi,

I have a form in usercontrol and add this control on runtime when user click "add more option".

There is product section where user enter product details but when they need to enter more product features then need to click on "add more option", after clicking on add more option usercontrol form is added to the page. But after entering data when I try fetch the vale from the control getting null error. I could get ascx user control controls value in my aspx code behind.

If any have any idea please reply.

Thanks
Rajesh

推荐答案

没有足够的细节,但是我认为您正在运行时添加用户控件,而不是用as?x声明. 在这种情况下,在回发时,您需要再次创建控件的实例并将其添加到页面,然后才能从中读取信息.最好的选择是在OnInit或Page_Load中.
Not enough detail, but I think you''re adding user control at runtime, not declarative in as?x.
In that case on post-back you need to make an instance of your control again and add it to the page before you can read from it. Best place to do this would be in OnInit or Page_Load.


这篇关于如何在代码背后获取用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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