动态加载的用户控件的 Page_Load 事件不会从处理程序触发。为什么?
我有一个处理程序 (.ashx) 文件,用于处理请求。根据所需输出的类型,我想加载一个用户控件,该控件将以正确的格式呈现数据。
我以为当我创建 MyUC 实例时,它的加载事件会触发,但我想不会。我什至尝试指定我自己的事件处理程序,但这不起作用。
值得注意的是,我可以创建 MyUC 的实例并将资金分配给其 Funds 属性。这是我需要实际使用该资金列表执行操作的加载事件!
这是我的代码,它不起作用。
private string GenerateList(IEnumerable<Fund> funds)
{
string html = "";
Page page = new Page();
MyUC myControl = (MyUC)page.LoadControl("MyUC.ascx");
myControl.Funds = funds;
myControl.Load += new EventHandler(myControl_Load);
return html;
}
谁能告诉我我做错了什么?我该如何修复它?
谢谢
戴夫
I have a handler (.ashx) file that I'm using to deal with Requests. Depending on the type of output needed, I want to load a user control that will present the data in the correct format.
I thought that when I created the instance of MyUC its load event would fire, but i guess not. I've even tried specifying my own event handler but that doesn't work.
For what it's worth noting, I can create the instance of the MyUC and assign the funds to its Funds property. It's the load event that I need to actually do stuff with that list of funds!
This is the code that i have, which doesn't work.
private string GenerateList(IEnumerable<Fund> funds)
{
string html = "";
Page page = new Page();
MyUC myControl = (MyUC)page.LoadControl("MyUC.ascx");
myControl.Funds = funds;
myControl.Load += new EventHandler(myControl_Load);
return html;
}
Can anyone tell me what I'm doing wrong? How can I go about fixing it?
Thanks
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要添加一个表单控件
HtmlForm
来呈现回发控件,然后使用 Server.Execute() 执行页面来源:
http://weblogs. asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templated-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx
http://www.west-wind.com/Weblog/posts/298307.aspx
You need to add a Form control
HtmlForm
to render postback controls and then execute the page using Server.Execute()Sources:
http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx
http://www.west-wind.com/Weblog/posts/298307.aspx