Dynamically Loaded User Control's Page_Load event Doesn't Fire from Handler. Why?
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 = f开发者_如何学Cunds;
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
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
精彩评论