I have a UC that gathers data. When the user is ready to process the data they click a Submit in the UC. That should send the data to the parent page. I'm getting confused about exactly what goes in the UC, what goes in the parent, and how to hook them up for the data exchange.
It seems when the parent does a Page_Load or Page_LoadComplete that I can set a delegate in the UC instance, but after everything is loaded the delegate in the UC is null. It's like the parent is working with a different instance at load time than what exists at runtime - or maybe. I have no problem working with delegates in Windows Forms so I'm guessing I'm missing something that's ASP.NET specific.
I know this is kinda vague, but can someone point me to a page with a simple example of the proper way to do this? Or maybe post some real basic guidelines for what needs to be done and when in each piece? C# would be preferred, VB is OK if required. Code specific to .NET 2.0 is also fine.
Thanks!!
Loading
StarbuckPosted May 29, 2006, 1:13 AM
It seems I need to reset the delegate in my UC on every connection. I guess this makes sense since there is nothing in session state that keeps the delegate set. Code is below in case someone wants to point out a better way to do this. Thanks!
public delegate void CallBack(string s); // this is a global in a class file
public partial class _Default : System.Web.UI.Page // this is the container page
{
CallBack function1;
protected void Page_Load(object sender, EventArgs e)
{
function1 = new CallBack(method2exec);
ChildUC1.SetDelegate(function1);
// this code is required on every connection because it's not preserved
}
public void method2exec(string s)
{
txtInfo.Text = "UC executed parent method"; // textbox on this page
}
}
public partial class ChildUC : System.Web.UI.UserControl // this is the user control
{
CallBack parentMethod;
protected void Button1_Click(object sender, EventArgs e) // button on this page
{
parentMethod("Child button clicked");
}
public void SetDelegate(CallBack foreignMethod)
{
parentMethod = foreignMethod;
}
}
As usual the answer comes almost as soon as I hit the Post button to ask the question - go figure.