【发布时间】:2012-01-18 17:38:17
【问题描述】:
我有 ASP.NET Web 应用程序,其中包含 MasterPage、ASPX 页面,我根据菜单选择将用户控件动态加载到包含 PlaceHolder 的 UpdatePanel 中。这工作正常。问题是我的用户控件中的任何事件都不起作用。我有不同的场景:
- DropDownList,其中选定的值应加载不同的用户控件
- LinkButton,其中 Click 事件应将不同的 UserControl 加载到 PlaceHolder(在父页面上)。
我现在已经花了 3 天的时间为此尝试了几件事.... 注册事件,使用接口等等....
但到目前为止没有任何效果:( ..感谢我能得到的任何帮助。
是的,我也在用户控件上尝试了 Page_PreInit 事件。 当我在用户控件中单击 LinkButton(或 DropDownList)时唯一触发的是父页面上的 Page_Load 事件。然后包含用户控件(我正在单击)的 PlaceHolder 具有 Contol.Count = null 这是一些代码
//Page_Load on parent page:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadDefaultControl(ctrlPlaceHolder, Base_Path + "_Services.ascx");
}
}
//我的用户控件中的Page_Load
protected void Page_Load(object sender, EventArgs e)
{
btJoomlaManagement.Click += btJoomlaManagement_Click;
}
父页面上的 PlaceHolder 位于 UpdatePanel >> ContentTemplate 内。
<asp:UpdatePanel ID="pnlControlContainer" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:PlaceHolder ID="ctrlPlaceHolder" runat="server" EnableViewState="False" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="menuServices" />
</Triggers>
</asp:UpdatePanel>
行为如下..当我加载我的 USerControl Page_Load 并运行 Click 事件时..当我单击我的用户控件中的链接按钮时,父页面上的 Page_Load 运行但我的用户控件中的 Click 方法不运行。用户控件(我刚刚单击了我的链接按钮)消失了。
所以我的事件(点击)不会触发......希望你能理解得更好一点。
【问题讨论】:
标签: asp.net .net c#-4.0 user-controls