Hi,
Don't use constructor in the control.
-------Control.cs---------
....
public event EventHandler OnClickRender;
protected void Click_RenderReport(object sender, EventArgs e)
{
if(OnClickRender != null)
OnClickRender(this, new EventArgs());
}
....
-------End Control.cs---------
-------Page.cs---------
protected void RenderReport(object sender, EventArgs e)
{
...
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
ReportOptions1.OnClickRender += new EventHandler(RenderReport);
}
-------End Page.cs---------
This sample shows you how your page can get event from the your control.
The page has the "RenderReport" method. And control has a button that has
"Click_RenderReport" event. You have to create public event in the your
control.
The "Click_RenderReport" method compare the "OnClickRender" event. Then you
have to add new method to the your page. For example: "RenderReport"
And the "OnInit" method must have line like this:
ReportOptions1.OnClickRender += new EventHandler(RenderReport);
If you rememeber, you created the "OnClickRender " public event. When you
press on the button in the control at that time your page can catch this
event. If you want to pass your datas to your control, you have to create a
public property. This is an example; At that time you can pass your
parameter to the control.
control.Email = "bla-bal";
public string Email
{
get
{
return txtEmail.Text.Trim();
}
set
{
txtEmail.Text = value;
}
}
bye-bye
"mortb" <mo****@hotmail.com> wrote in message
news:eq**************@TK2MSFTNGP12.phx.gbl...
HI all,
I'm writing a control that resides on a page which instantiates an object
from the database.
My goal is to make the control use the same object for the control as on
the page.
Something like this:
Page code behind (C#):
private void Page_Load(object sender, System.EventArgs e)
{
int objId = Request.QueryString("id");
mytype obj = getobjfromDb(objid);
MyControl theControl = new MyContro(obj);
}
Control code:
public class MyControl: WebControl, INamingContainer
{
public MyControl(mytype myObject)
{
myobj = myObject;
}
protected override void OnLoad(EventArgs e)
{
this.controls.add(new literal(myojbj.ToString());
}
private mytype myobj;
}
I find this difficult to acheive as I can't really get a grasp of the
event firing order.
* Where can I call the contructor of the control?
* How will the events find their way back to my control?
* Is the implementation of controls described in depth some where?
(Something more than
http://msdn.microsoft.com/library/de...nLifecycle.asp) * Is the process the page framwork goes through when processign a request
discussed somewhere?
cheers,
mortb