Here's my attempt (does kind of what you are doing); look at the trace =
and you'll see the posted back values when you click on the "Button". =
Note there are a lot of ways to handle the TextBoxes, in my example I'm =
just searching for them, but you could do something else (probably =
better).
To answer your question about when does CreateChildControls get called, =
it gets called when the control tree calls the Controls property. In the =
initial case this is likely to happen in PreRender when the framework =
asks for all of the Controls for a control and asks to render each =
control; later on when doing event handling etc.
Scott
<%@ Page language=3D"c#" AutoEventWireup=3D"false" Trace=3D"true" %>
<%@ Import Namespace=3D"Microsoft.Web.UI.WebControls" %>
<html>
<head>
<script language=3D"C#" runat=3D"server">
MultiTabCompositeControl tab;
protected override void OnInit(EventArgs e)
{
tab =3D new MultiTabCompositeControl();
this.PlaceHolder1.Controls.Add(tab);
}
=20
public void Button1_Click(object sender, System.EventArgs e) {
tab.TraceTextBoxes();
}
=20
public class MultiTabCompositeControl : System.Web.UI.Control, =
INamingContainer {
public ControlCollection Controls {
get {
this.EnsureChildControls();
return base.Controls;
}
}
=20
TabStrip FormTabs;
MultiPage FormPages;
=20
TextBox tb0;
TextBox tb1;
protected override void CreateChildControls() {
this.Controls.Clear();
=20
FormTabs =3D new TabStrip();
FormTabs.ID =3D "TS";
Controls.Add(FormTabs);
=20
if (!this.Page.IsPostBack)
{
Tab t =3D new Tab();
t.Text =3D "One";
FormTabs.Items.Add(t);
=20
t =3D new Tab();
t.Text =3D "Two";
FormTabs.Items.Add(t);
}
=20
FormPages =3D new MultiPage();
FormPages.ID =3D "MP";
for (int i =3D 0; i < 2; i++)
{
PageView pv =3D new PageView();
Label l =3D new Label();
l.ID =3D "LB" + i;
l.Text =3D "Label " + i;
pv.Controls.Add(l);
TextBox tb =3D new TextBox();
if (i =3D=3D 0) tb0 =3D tb; else tb1 =3D tb;
tb.ID =3D "TB" + i;
pv.Controls.Add(tb);
FormPages.Controls.Add(pv);
}
=20
FormTabs.TargetID =3D "MP";
=20
Controls.Add(FormPages);
=20
this.ChildControlsCreated =3D true;
}
=20
public void TraceTextBoxes() {
TextBox tb =3D LocateControl(this, "TB0") as TextBox;
if (tb !=3D null) {
this.Page.Trace.Warn("TB0 =3D " + tb.Text);
}
tb =3D LocateControl(this, "TB1") as TextBox;
if (tb !=3D null) {
this.Page.Trace.Warn("TB1 =3D " + tb.Text);
}
}
=20
private static System.Web.UI.Control =
LocateControl(System.Web.UI.Control root, string name) {
if (root =3D=3D null || name =3D=3D null) {
return null;
}
foreach (System.Web.UI.Control c in root.Controls) {
if (c.ID !=3D null && c.ID.EndsWith(name)) {
return c;
}
if (c.Controls.Count > 0) {
System.Web.UI.Control t =3D LocateControl(c, name);
if ( t !=3D null ) {
return t;
}
}
}
return null;
}
}
</script>
<meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dutf-8">
<meta name=3D"GENERATOR" content=3D"Microsoft Visual Studio 7.0">
<meta name=3D"CODE_LANGUAGE" content=3D"C#">
<meta name=3D"vs_defaultClientScript" content=3D"JavaScript">
<meta name=3D"vs_targetSchema" =
content=3D"
http://schemas.microsoft.com/intellisense/ie5"> </head>
<body>
<form id=3D"Form1" method=3D"post" runat=3D"server">
<p>
<asp:placeholder id=3D"PlaceHolder1" =
runat=3D"server"></asp:placeholder></p>
<p>
<asp:button id=3D"Button1" runat=3D"server" text=3D"Button" =
onclick=3D"Button1_Click"></asp:button></p>
</form>
</body>
</html>
[quoted text, click to view] "Russ" <russk2@eticomm.net> wrote in message =
news:sq46e014punugue9gh8c9t3katftqfrtg0@4ax.com...
Hi again Scott. Ok, I have tried what you suggested as well as I can
comprehend and have failed again. The new control class appears to do
nothing - not even display. I created a composite control class along
the lines you suggested, after doing the reading you suggested. Then
I created an instance of the new class, setting it's data members to
contain the information needed to create all the pages and controls.
When it did not work, I tried placing a breakpoint in the
CreateChildControls routine, and it never gets there. When is that
routine supposed to be called?
Below is the code I used, with some settings omitted for brevity. (I
didn't assign any id's to the TextBoxes yet because I just want to see
it display properly before starting to worry about getting the data
out.)
Thanks for any additional help you can provide.
Russ
In my class definition:
MultiTabCompositeControl TabCtrl;
In Page_Load (not within IsPostBack):
TabCtrl =3D new MultiTabCompositeControl ();
TabCtrl.nRates =3D (int) Ed.nRates;
TabCtrl.Er =3D Ed.Rd; // The array of rate data
// The composite class
public class MultiTabCompositeControl : Control, INamingContainer=20
{
public override ControlCollection Controls=20
{
get { this.EnsureChildControls(); return base.Controls; }
}
public int nRates; // number of pages needed
public CEmpRateData [] Er;
TabStrip FormTabs;
MultiPage FormPages;
protected override void CreateChildControls ()=20
{
this.Controls.Clear ();
FormTabs =3D new TabStrip (); // important that is
created...
FormTabs.ID =3D "TS";
FormTabs.Style.Add ("POSITION", "absolute");
FormTabs.Style.Add ("LEFT", "10px");
FormTabs.Style.Add ("TOP", "280px");
.
.
FormPages =3D new MultiPage ();
FormPages.ID =3D "FP";
FormPages.Style.Add ("POSITION", "absolute");
FormPages.Style.Add ("LEFT", "10px");
.
.
for (int i=3D0; i < nRates; ++i) {
CEmpRateData ERate =3D Er [i];
if (! Page.IsPostBack) { // don't create the tabs
// if ViewState is active
Tab t =3D new Tab ();
t.Text =3D "Rate " + (ERate.m_Rate + 1);
FormTabs.Items.Add (t);
}
PageView pv =3D new PageView ();
FormPages.Controls.Add (pv);
AddField (pv, "Regular Hours", 115,20, 40, 10);
AddField (pv, "Overtime Hours", 115,50, 40, 10);
.
.
}
Controls.Add (FormTabs);