在asp.net中动态用户控件 [英] Dynamic User Controls in asp.net

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

问题描述

您好,我想李尔如何在asp.net中动态创建的用户控件。

Hello I am trying to lear how to create Dynamic User Controls in asp.net.

我只知道,这种类型的控件创建或在运行时加载。

I just know that this type of controls are created or loaded at run time.

有人知道这个问题一个很好的教程?

Someone knows a good tutorial about this topic?

在预先感谢

推荐答案

您可以了解在ASP.Net web表单动态控制的最好的事情是如何避免它们。在asp.net动态控件都充满了陷阱。我几乎总是推荐以下备选方案之一:

The best thing you can learn about dynamic controls in ASP.Net webforms is how to avoid them. Dynamic controls in asp.net are filled with pitfalls. I almost always recommend one of the following alternatives:


  • 将控件一个合理的固定数量的页面上,然后只显示你需要的人。

  • 弄清楚动态控制和源抽象出来给你可以绑定到一个中继器,即使它只是Enumerable.Range()的调用数据源(数组,IEnumerable的,列表等)。

  • 构建一个输出想要的HTML,绕过了整个控制比喻该内容的用户的控制。

如果你真的必须的动态控制的工作,是要保持HTTP的无状态特性于心,用的 asp.net页面生命周期。每增加它自己的皱纹,以使动态控制的工作:前者,你需要创建或重新创建控件每次你做回发的时间,而后者,你需要做的的命中页面加载事件 - 通常是在页面初始化或pre-INIT

If you really must work with dynamic controls, it's important to keep the stateless nature of http in mind, along with the asp.net page life cycle. Each adds it's own wrinkle to making dynamic controls work: the former that you need to create or recreate the controls every time you do a postback, and the latter that you need to do this before hitting the page load event - usually in page init or pre-init.

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

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