Child Neglect

Discussion in 'ASP .Net' started by wASP, Aug 8, 2005.

  1. wASP

    wASP Guest

    Hi,

    I was under the impression that, when ASP rendered a page,
    it recursively traversed the hierarchy, executing all controls
    in each ControlCollection of every control in that hierarchy.

    I tried adding a Button control to a TextBox ControlCollection,
    and it didn't execute. When I add the control to the Placeholder
    ControlCollection (after the TextBox control is added), it executes
    without any problem:
    /* . . . . . . . . . . . . . . . . */
    protected void create_ctrl_pair_0x
    (String text_box_id, String Btn_ID, String Btn_text)
    {
    ControlCollection crnt_ctrl = CCP_Dyn_Ctrl_Placeholder.Controls;

    // Create UserTextBox TextBox control.

    UserTextBox0x = new TextBox ();

    // Configure the UserTextBox TextBox control.
    UserTextBox0x.ID = text_box_id;

    // Add UserTextBox TextBox control to the Controls collection
    // of the Dyn_Control_Placeholder PlaceHolder control.

    crnt_ctrl.Add (UserTextBox0x);
    crnt_ctrl.Add ( new LiteralControl("<br>XxXxXxXxXxXxXxXxX<br><br>") );

    // Create and initialize a Button.

    button0x = new Button();
    button0x.ID = Btn_ID;
    button0x.Text = Btn_text;

    // make the button a child of the text box control.
    crnt_ctrl = UserTextBox0x.Controls;

    crnt_ctrl.Add (button0x);
    crnt_ctrl.Add
    ( new LiteralControl("<br>===================<br><br>") );
    }
    /* . . . . . . . . . . . . . . . . */
    /* | | | | | | | | | | | | | | | | */
    /* . . . . . . . . . . . . . . . . */



    If this assignment statement is removed from the above:
    crnt_ctrl = UserTextBox0x.Controls;
    ... it works fine. Otherwise, there is no button, as the child is neglected.



    Can anyone give me an idea as to what I would have to do to make this work?



    My complete code is as follows:
    <+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>
    <+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>
    <%@ Page Language="C#" AutoEventWireup="True" %>

    <html>
    <head>

    <script runat="server">

    /* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
    /* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
    // protected class sys_obj_class
    public class sys_obj_class
    {
    private Page this_page01;
    public Page Get_this_page01
    { get { return this_page01; } }

    private PlaceHolder Obj_Dyn_Ctrl_Placeholder;
    public PlaceHolder Get_Obj_Dyn_Ctrl_Placeholder
    { get { return Obj_Dyn_Ctrl_Placeholder; } }

    private Label Obj_Dyn_Label01;
    public Label Get_Obj_Dyn_Label01
    { get { return Obj_Dyn_Label01; } }


    public sys_obj_class
    (PlaceHolder Dyn_Ctrl_Placeholder, Label Dyn_Label)
    {
    this_page01 = Dyn_Ctrl_Placeholder.Page;
    Obj_Dyn_Ctrl_Placeholder = Dyn_Ctrl_Placeholder;
    Obj_Dyn_Label01 = Dyn_Label;
    }
    }

    /* ------------------------------------------------------------------ */
    /* ------------------------------------------------------------------ */
    public void Page_Init (object sender, EventArgs e)
    {
    int ndx = 2;

    Dyn_Control_Placeholder.Controls.Add
    ( new LiteralControl("<br>||| added 1 on init |||<br><br>") );
    }
    /* ------------------------------------------------------------------ */
    /* ------------------------------------------------------------------ */
    protected void Page_Load (Object sender, EventArgs e)
    {
    PlaceHolder plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_Placeholder");
    Label lbl_msg01 = (Label) FindControl ("Message01");
    sys_obj_class sys_obj = new sys_obj_class (plc_hldr, lbl_msg01);

    ctrl_pair_creation_01 ccp1 = new ctrl_pair_creation_01 (sys_obj);

    ccp1.create_ctrl_pair_01 ();
    }
    /* ------------------------------------------------------------------ */
    /* ------------------------------------------------------------------ */

    /* - - - - - - - - - - - - - - - - - - - - - - */
    /* - - - - - - - - - - - - - - - - - - - - - - */
    /* - - - - - - - - - - - - - - - - - - - - - - */
    protected class base_create_ctrl_pair
    {
    protected TextBox UserTextBox0x;
    protected Button button0x;
    protected PlaceHolder CCP_Dyn_Ctrl_Placeholder;
    protected Label Dyn_Lbl_msg01;

    /* =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= *
    <<< constructor >>>
    * =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= */
    protected base_create_ctrl_pair (sys_obj_class sys_obj)
    {
    CCP_Dyn_Ctrl_Placeholder = sys_obj.Get_Obj_Dyn_Ctrl_Placeholder;
    Dyn_Lbl_msg01 = sys_obj.Get_Obj_Dyn_Label01;
    }
    /* =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= */
    /* =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= */

    protected void init_single_line_text_box (TextBox new_TextBox, int col_sz)
    { new_TextBox.Columns = col_sz; }

    /* . . . . . . . . . . . . . . . . */
    protected void create_ctrl_pair_0x
    (String text_box_id, String Btn_ID, String Btn_text)
    {
    ControlCollection crnt_ctrl = CCP_Dyn_Ctrl_Placeholder.Controls;

    // Create UserTextBox TextBox control.

    UserTextBox0x = new TextBox ();

    // Configure the UserTextBox TextBox control.
    UserTextBox0x.ID = text_box_id;

    // Add UserTextBox TextBox control to the Controls collection
    // of the Dyn_Control_Placeholder PlaceHolder control.

    crnt_ctrl.Add (UserTextBox0x);
    crnt_ctrl.Add ( new LiteralControl("<br>XxXxXxXxXxXxXxXxX<br><br>") );

    // Create and initialize a Button.

    button0x = new Button();
    button0x.ID = Btn_ID;
    button0x.Text = Btn_text;

    // make the button a child of the text box control.
    crnt_ctrl = UserTextBox0x.Controls;

    crnt_ctrl.Add (button0x);
    crnt_ctrl.Add
    ( new LiteralControl("<br>===================::::<br><br>") );
    }
    /* . . . . . . . . . . . . . . . . */


    /* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- *
    <<< Button Click Handlers >>>
    * -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
    private String submit_click_str01 = "The TextBox";

    private String submit_click_str02
    = " control above is dynamically generated. <br> You entered: ";

    public void Submit_Click (Object sender, EventArgs e)
    { // Retrieve the UserTextBox TextBox control from the
    Dyn_Control_Placeholder
    // PlaceHolder control.
    TextBox TempTextBox = (TextBox)
    CCP_Dyn_Ctrl_Placeholder.FindControl("UserTextBox1");

    // Display the Text property.
    Dyn_Lbl_msg01.Text = submit_click_str01 + '1' + submit_click_str02 +
    TempTextBox.Text;
    }
    /* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
    /* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */

    }
    /* - - - - - - - - - - - - - - - - - - - - - - */
    /* END: protected class base_create_ctrl_pair */
    /* - - - - - - - - - - - - - - - - - - - - - - */

    /* /|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\ */
    protected class ctrl_pair_creation_01 : base_create_ctrl_pair
    {
    private sys_obj_class lcl_sys_obj;

    // constructor
    public ctrl_pair_creation_01 (sys_obj_class sys_obj) : base (sys_obj)
    { lcl_sys_obj = sys_obj; }

    /* . . . . . . . . . . . . . */
    public void create_ctrl_pair_01 ()
    { create_ctrl_pair_0x
    ("UserTextBox1", "DButton01", "Submit 01");

    button0x.Click += new EventHandler (Submit_Click);

    if (!lcl_sys_obj.Get_this_page01.IsPostBack)
    init_single_line_text_box (UserTextBox0x, 22);
    }
    /* . . . . . . . . . . . . . */
    }
    /* /|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\ */
    /* /|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\ */

    </script>
    </head>

    <body>

    <form runat="server">

    <h3> Control Init </h3>

    Enter some text and click the Submit button. <br><br>

    <asp:placeHolder ID="Dyn_Control_Placeholder" runat="server"/>

    <asp:Label ID="Message01" runat="server"/>

    </form>

    </body>
    </html>

    <+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>
    <+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>



    THANKS!!!



    - wASP
     
    wASP, Aug 8, 2005
    #1
    1. Advertising

  2. wASP

    Bruce Barker Guest

    not quite. the page renders all its children. if the one of the form
    controls supports children of its own, it renders them.

    the default implemenation of Render is RenderChildren. the TextBox overrides
    the render with its own, and never calls RenderChildren (because the TextBox
    does not support children).

    -- bruce (sqlwork.com)




    "wASP" <wylbur[at]ev1[dot]net> wrote in message
    news:...
    >
    > Hi,
    >
    > I was under the impression that, when ASP rendered a page,
    > it recursively traversed the hierarchy, executing all controls
    > in each ControlCollection of every control in that hierarchy.
    >
    > I tried adding a Button control to a TextBox ControlCollection,
    > and it didn't execute. When I add the control to the Placeholder
    > ControlCollection (after the TextBox control is added), it executes
    > without any problem:
    > /* . . . . . . . . . . . . . . . . */
    > protected void create_ctrl_pair_0x
    > (String text_box_id, String Btn_ID, String Btn_text)
    > {
    > ControlCollection crnt_ctrl = CCP_Dyn_Ctrl_Placeholder.Controls;
    >
    > // Create UserTextBox TextBox control.
    >
    > UserTextBox0x = new TextBox ();
    >
    > // Configure the UserTextBox TextBox control.
    > UserTextBox0x.ID = text_box_id;
    >
    > // Add UserTextBox TextBox control to the Controls collection
    > // of the Dyn_Control_Placeholder PlaceHolder control.
    >
    > crnt_ctrl.Add (UserTextBox0x);
    > crnt_ctrl.Add ( new
    > LiteralControl("<br>XxXxXxXxXxXxXxXxX<br><br>") );
    >
    > // Create and initialize a Button.
    >
    > button0x = new Button();
    > button0x.ID = Btn_ID;
    > button0x.Text = Btn_text;
    >
    > // make the button a child of the text box control.
    > crnt_ctrl = UserTextBox0x.Controls;
    >
    > crnt_ctrl.Add (button0x);
    > crnt_ctrl.Add
    > ( new LiteralControl("<br>===================<br><br>") );
    > }
    > /* . . . . . . . . . . . . . . . . */
    > /* | | | | | | | | | | | | | | | | */
    > /* . . . . . . . . . . . . . . . . */
    >
    >
    >
    > If this assignment statement is removed from the above:
    > crnt_ctrl = UserTextBox0x.Controls;
    > ... it works fine. Otherwise, there is no button, as the child is
    > neglected.
    >
    >
    >
    > Can anyone give me an idea as to what I would have to do to make this
    > work?
    >
    >
    >
    > My complete code is as follows:
    > <+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>
    > <+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>
    > <%@ Page Language="C#" AutoEventWireup="True" %>
    >
    > <html>
    > <head>
    >
    > <script runat="server">
    >
    > /* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
    > */
    > /* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
    > */
    > // protected class sys_obj_class
    > public class sys_obj_class
    > {
    > private Page this_page01;
    > public Page Get_this_page01
    > { get { return this_page01; } }
    >
    > private PlaceHolder Obj_Dyn_Ctrl_Placeholder;
    > public PlaceHolder Get_Obj_Dyn_Ctrl_Placeholder
    > { get { return Obj_Dyn_Ctrl_Placeholder; } }
    >
    > private Label Obj_Dyn_Label01;
    > public Label Get_Obj_Dyn_Label01
    > { get { return Obj_Dyn_Label01; } }
    >
    >
    > public sys_obj_class
    > (PlaceHolder Dyn_Ctrl_Placeholder, Label Dyn_Label)
    > {
    > this_page01 = Dyn_Ctrl_Placeholder.Page;
    > Obj_Dyn_Ctrl_Placeholder = Dyn_Ctrl_Placeholder;
    > Obj_Dyn_Label01 = Dyn_Label;
    > }
    > }
    >
    > /* ------------------------------------------------------------------ */
    > /* ------------------------------------------------------------------ */
    > public void Page_Init (object sender, EventArgs e)
    > {
    > int ndx = 2;
    >
    > Dyn_Control_Placeholder.Controls.Add
    > ( new LiteralControl("<br>||| added 1 on init |||<br><br>") );
    > }
    > /* ------------------------------------------------------------------ */
    > /* ------------------------------------------------------------------ */
    > protected void Page_Load (Object sender, EventArgs e)
    > {
    > PlaceHolder plc_hldr = (PlaceHolder) FindControl
    > ("Dyn_Control_Placeholder");
    > Label lbl_msg01 = (Label) FindControl ("Message01");
    > sys_obj_class sys_obj = new sys_obj_class (plc_hldr, lbl_msg01);
    >
    > ctrl_pair_creation_01 ccp1 = new ctrl_pair_creation_01 (sys_obj);
    >
    > ccp1.create_ctrl_pair_01 ();
    > }
    > /* ------------------------------------------------------------------ */
    > /* ------------------------------------------------------------------ */
    >
    > /* - - - - - - - - - - - - - - - - - - - - - - */
    > /* - - - - - - - - - - - - - - - - - - - - - - */
    > /* - - - - - - - - - - - - - - - - - - - - - - */
    > protected class base_create_ctrl_pair
    > {
    > protected TextBox UserTextBox0x;
    > protected Button button0x;
    > protected PlaceHolder CCP_Dyn_Ctrl_Placeholder;
    > protected Label Dyn_Lbl_msg01;
    >
    > /*
    > =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= *
    > <<< constructor >>>
    > *
    > =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= */
    > protected base_create_ctrl_pair (sys_obj_class sys_obj)
    > {
    > CCP_Dyn_Ctrl_Placeholder =
    > sys_obj.Get_Obj_Dyn_Ctrl_Placeholder;
    > Dyn_Lbl_msg01 = sys_obj.Get_Obj_Dyn_Label01;
    > }
    > /*
    > =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= */
    > /*
    > =#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= */
    >
    > protected void init_single_line_text_box (TextBox new_TextBox,
    > int col_sz)
    > { new_TextBox.Columns = col_sz; }
    >
    > /* . . . . . . . . . . . . . . . .
    > */
    > protected void create_ctrl_pair_0x
    > (String text_box_id, String Btn_ID, String Btn_text)
    > {
    > ControlCollection crnt_ctrl =
    > CCP_Dyn_Ctrl_Placeholder.Controls;
    >
    > // Create UserTextBox TextBox control.
    >
    > UserTextBox0x = new TextBox ();
    >
    > // Configure the UserTextBox TextBox control.
    > UserTextBox0x.ID = text_box_id;
    >
    > // Add UserTextBox TextBox control to the Controls collection
    > // of the Dyn_Control_Placeholder PlaceHolder control.
    >
    > crnt_ctrl.Add (UserTextBox0x);
    > crnt_ctrl.Add ( new
    > LiteralControl("<br>XxXxXxXxXxXxXxXxX<br><br>") );
    >
    > // Create and initialize a Button.
    >
    > button0x = new Button();
    > button0x.ID = Btn_ID;
    > button0x.Text = Btn_text;
    >
    > // make the button a child of the text box control.
    > crnt_ctrl = UserTextBox0x.Controls;
    >
    > crnt_ctrl.Add (button0x);
    > crnt_ctrl.Add
    > ( new
    > LiteralControl("<br>===================::::<br><br>") );
    > }
    > /* . . . . . . . . . . . . . . . .
    > */
    >
    >
    >
    > /* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
    > *
    > <<< Button Click Handlers >>>
    >
    > * -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
    > */
    > private String submit_click_str01 = "The TextBox";
    >
    > private String submit_click_str02
    > = " control above is dynamically generated. <br> You
    > entered: ";
    >
    > public void Submit_Click (Object sender, EventArgs e)
    > { // Retrieve the UserTextBox TextBox control from the
    > Dyn_Control_Placeholder
    > // PlaceHolder control.
    > TextBox TempTextBox = (TextBox)
    > CCP_Dyn_Ctrl_Placeholder.FindControl("UserTextBox1");
    >
    > // Display the Text property.
    > Dyn_Lbl_msg01.Text = submit_click_str01 + '1' +
    > submit_click_str02 +
    > TempTextBox.Text;
    > }
    >
    > /* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
    > */
    >
    > /* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
    > */
    >
    > }
    > /* - - - - - - - - - - - - - - - - - - - - - - */
    > /* END: protected class base_create_ctrl_pair */
    > /* - - - - - - - - - - - - - - - - - - - - - - */
    >
    > /* /|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\ */
    > protected class ctrl_pair_creation_01 : base_create_ctrl_pair
    > {
    > private sys_obj_class lcl_sys_obj;
    >
    > // constructor
    > public ctrl_pair_creation_01 (sys_obj_class sys_obj) : base
    > (sys_obj)
    > { lcl_sys_obj = sys_obj; }
    >
    > /* . . . . . . . . . . . . . */
    > public void create_ctrl_pair_01 ()
    > { create_ctrl_pair_0x
    > ("UserTextBox1", "DButton01", "Submit 01");
    >
    > button0x.Click += new EventHandler (Submit_Click);
    >
    > if (!lcl_sys_obj.Get_this_page01.IsPostBack)
    > init_single_line_text_box (UserTextBox0x, 22);
    > }
    > /* . . . . . . . . . . . . . */
    > }
    > /* /|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\ */
    > /* /|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\_/|\ */
    >
    > </script>
    > </head>
    >
    > <body>
    >
    > <form runat="server">
    >
    > <h3> Control Init </h3>
    >
    > Enter some text and click the Submit button. <br><br>
    >
    > <asp:placeHolder ID="Dyn_Control_Placeholder" runat="server"/>
    >
    > <asp:Label ID="Message01" runat="server"/>
    >
    > </form>
    >
    > </body>
    > </html>
    >
    > <+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>
    > <+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>-<+>
    >
    >
    >
    > THANKS!!!
    >
    >
    >
    > - wASP
     
    Bruce Barker, Aug 9, 2005
    #2
    1. Advertising

  3. wASP

    wASP Guest

    On Mon, 8 Aug 2005 17:34:19 -0700, "Bruce Barker" <>
    wrote:

    >not quite. the page renders all its children. if the one of the form
    >controls supports children of its own, it renders them.
    >
    >the default implemenation of Render is RenderChildren. the TextBox overrides
    >the render with its own, and never calls RenderChildren (because the TextBox
    >does not support children).
    >
    >-- bruce (sqlwork.com)


    I'm thinking that this behavior can be overridden ... maybe?

    The first question that springs into my mind is that,
    if the TextBox does not support children (the lousy deadbeat),
    then why would it have a ControlCollection?

    I'll start digging through the docs ...


    - wASP
     
    wASP, Aug 9, 2005
    #3
  4. wASP

    rl Guest

    Why would you want a TextBox to contain a Button as a child? Always
    think about the final HTML that is the eventual target of all these
    ASP.NET objects. Having a button as a child of a TextBox would
    generate invalid HTML:

    <input type="text"><input type="submit" /></input>

    If what you want is to have a Button that immediately follows a
    TextBox, then the HTML you want is:

    <input type="text" /><input type="submit" />

    And in this case the Button is NOT a child of the TextBox. Remember
    that "child of" means "contained by" and now "follows."

    Try adding the Button as a child of the Page (or the Control, if that's
    where the TextBox is) and specifying the index at which to add the
    control:

    Page.Controls.AddAt(Page.Controls.IndexOf(tx),bt);

    You can also use a Panel or Placeholder control to contain both the
    TextBox and the Button:

    pnl.Controls.AddAt(pnl.Controls.IndexOf(tx),bt);

    rl

    wASP wrote:
    > On Mon, 8 Aug 2005 17:34:19 -0700, "Bruce Barker" <>
    > wrote:
    >
    > >not quite. the page renders all its children. if the one of the form
    > >controls supports children of its own, it renders them.
    > >
    > >the default implemenation of Render is RenderChildren. the TextBox overrides
    > >the render with its own, and never calls RenderChildren (because the TextBox
    > >does not support children).
    > >
    > >-- bruce (sqlwork.com)

    >
    > I'm thinking that this behavior can be overridden ... maybe?
    >
    > The first question that springs into my mind is that,
    > if the TextBox does not support children (the lousy deadbeat),
    > then why would it have a ControlCollection?
    >
    > I'll start digging through the docs ...
    >
    >
    > - wASP
     
    rl, Aug 9, 2005
    #4
  5. wASP

    wASP Guest

    On 9 Aug 2005 05:29:04 -0700, "rl" <> wrote:

    >Why would you want a TextBox to contain a Button as a child? Always
    >think about the final HTML that is the eventual target of all these
    >ASP.NET objects. Having a button as a child of a TextBox would
    >generate invalid HTML:
    >
    ><input type="text"><input type="submit" /></input>
    >
    >If what you want is to have a Button that immediately follows a
    >TextBox, then the HTML you want is:
    >
    ><input type="text" /><input type="submit" />
    >
    >And in this case the Button is NOT a child of the TextBox. Remember
    >that "child of" means "contained by" and now "follows."


    *NOW* I get it.

    I had a basic misunderstanding as to the implications of making
    the button control a child of the textbox control - that is until
    you clued me in with your post.


    >Try adding the Button as a child of the Page (or the Control, if that's
    >where the TextBox is) and specifying the index at which to add the
    >control:
    >
    >Page.Controls.AddAt(Page.Controls.IndexOf(tx),bt);
    >
    >You can also use a Panel or Placeholder control to contain both the
    >TextBox and the Button:
    >
    >pnl.Controls.AddAt(pnl.Controls.IndexOf(tx),bt);


    THAT is what I need to do.

    I appreciate your efforts to enlighten me on this issue.


    THANKS rl!!!


    - wASP
     
    wASP, Aug 9, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bhchng
    Replies:
    0
    Views:
    665
    bhchng
    Jan 13, 2004
  2. davout
    Replies:
    0
    Views:
    554
    davout
    Apr 18, 2004
  3. leon
    Replies:
    0
    Views:
    432
  4. Bryan Ax
    Replies:
    6
    Views:
    550
    Peter Flynn
    May 17, 2006
  5. Jeff Rodriguez
    Replies:
    23
    Views:
    1,141
    David Schwartz
    Dec 9, 2003
Loading...

Share This Page