简体   繁体   English

根据其他控件事件动态加载用户控件

[英]Load User Controls dynamically based on other control events

I have a "cross section" of variables that I need to use to generate a set of user controls dynamically. 我有一个变量的“横截面”,我需要用它来动态生成一组用户控件。 In the center of the page I have a Telerik multitab/page. 在页面中心,我有一个Telerik多选项卡/页面。 I have a custom tree menu and a custom menubar, based on the combination of menu input each of the tabs should load a user control relevant to that cross section of data. 我有一个自定义树菜单和一个自定义菜单栏,基于菜单输入的组合,每个选项卡都应加载与该数据横截面相关的用户控件。

For clarity, almost each tab, treeview, menubar combination needs a unique control. 为了清楚起见,几乎每个选项卡,树视图,菜单栏组合都需要一个唯一的控件。

My problem is that all the postback/loading happens well before the "OnMenuChanged" event triggers, so I'm one "set" of user controls behind. 我的问题是所有回发/加载都在“ OnMenuChanged”事件触发之前发生,所以我是后面的一组“用户”控件。 Even if I were to use session/viewstate they wouldn't get assigned until after I needed the value stored in them. 即使我要使用session / viewstate,也要等到我需要存储在其中的值后,才能分配它们。

Currently what is happening is the default user controls are loaded in the "pageviewcreated" event, then in the onMenuItemChanged I go back and reload the user controls. 当前正在发生的是在“ pageviewcreated”事件中加载了默认的用户控件,然后在onMenuItemChanged中返回并重新加载了用户控件。 It seems very inefficient and is complicating up the approach for selecting the right .ascx. 看来效率很低,并且使选择正确的.ascx的方法变得复杂。

How do I manage this? 我该如何处理?

If I understand what you're trying to do could you not use a placeholder control and inject your needed usercontrol into that inside of the events you're managing? 如果我了解您要执行的操作,是否可以不使用占位符控件,而是将所需的用户控件注入到您要管理的事件中呢? Try doing something like this inside of the "OnMenuSelected" event. 尝试在“ OnMenuSelected”事件内部执行类似的操作。

 WebUserControl1 uc = (WebUserControl1) Page.LoadControl("WebUserControl1.ascx"); 
 PlaceHolder1.Controls.Add(uc); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM