Dynamically create non-fixed number of TextBoxes in Composite Control

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Dynamically create non-fixed number of TextBoxes in Composite Control

    Hi,

    I have a composite control(TextBoxControl.cs) in my
    DynamicTextBox.aspx. On the Page_Load of the
    DynamicTextBox.aspx page, I am calling a business tier
    assembly, which is returning an ArrayList containing an
    unknown amount of objects. I would like to pass this
    ArrayList to my composite control and for each object in
    the ArrayList, I would like to build and populate a
    TextBox. The reason I need to pass the data to the
    composite control is because I would like to reuse this
    control on multiple pages in the application.

    Currently, I am able to get the data from the business
    tier assembly directly from the composite control's
    CreateChildControls() method, and create the Textboxes.
    The problem I am having is passing the data from the
    Page_Load event of the parent DynamicTextBox.aspx and
    having the controls show up on the page. The data gets to
    the control's CreateChildControls() event and I watch it
    in Debug go through and create the controls, but when the
    page renders, the controls are not there. What gives? I
    tried passing the data from the DynamicTextBox.aspx
    page's On_Init, but the same result as Page_Load occured.

    Does anyone know why the TextBoxes are not rendering or
    have any insight as to what I am doing wrong?



    Thanks in advance for your time and help,

    Paul
    Paul Guest

  2. Similar Questions and Discussions

    1. Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created)
      Ok here's my scenario. I have a Custom Composite Server Control (CCSC) consisting of a TextBox, Button & Panel. (And some other code - which I...
    2. Composite Web Control and Dynamically Created Children Controls.
      Hi I am developing a web control which creates other web controls. During the OnInit of the my web control I read an Xml file which tells my web...
    3. Dynamically create datagrid control
      Hi, You have to to declare it on the aspx side at all. Just do it all in the code will be much more easier and convenient! HTHs... R. Thomas ...
    4. Possible to create a composite control that has a child control that is a validator that validates the composite control itself?
      I am attempting to create a composite control which has a label, followed by an optional error message, followed by two text boxes. I have...
    5. Dynamically Added TextBoxes
      Is there anyway to get the value of a dynamically added textbox that was added after OnInit in Page_Load on Postback? Page_Load Dim tb As...
  3. #2

    Default Re: Dynamically create non-fixed number of TextBoxes in Composite Control

    "Paul" <pauljanisko@hotmail.com> wrote in message
    news:047201c35d36$fc66ab70$a401280a@phx.gbl...
    > Hi,
    >
    > Does anyone know why the TextBoxes are not rendering or
    > have any insight as to what I am doing wrong?
    Paul, I suggest you read up on creating DataBound controls. "Developing
    Microsoft® ASP.NET Server Controls and Components" from MS Press, by Nikhil
    Kothari and Vandana Datye ([url]http://www.microsoft.com/mspress/books/5728.asp[/url])
    is the best book I've seen on the subject.
    > Thanks in advance for your time and help,
    I've never created a data bound control, but from what I recall reading, you
    don't want to create the controls in CreateChildControls, but rather in
    DataBind. Also, you'll want to be able to recreate the controls from
    ViewState in CreateChildControls. The book above recommends having a common
    control-creation method called both by DataBind and by CreateChildControls -
    they call theirs CreateControlHierarchy, and it takes a bool to tell it
    whether to use the data source or to use ViewState.
    --
    John Saunders
    Internet Engineer
    [email]john.saunders@surfcontrol.com[/email]



    John Saunders Guest

  4. #3

    Default Re: Dynamically create non-fixed number of TextBoxes in Composite Control

    Thanks John. I reviewed the book you recommended and
    will order it.

    I am still unclear how to pass data to the control before
    the textboxes are rendered. Unfortunately our deadline
    is such that I can't take the gamble of thinking I can
    figure it out using the book. If I can't find an answer,
    I will have to move to code directly into the page as
    opposed to using a control. Even then I am unsure if
    that will work.

    Thanks for your help. Anyone have any ideas?



    Thanks,

    Paul
    Paul Guest

  5. #4

    Default Re: Dynamically create non-fixed number of TextBoxes in Composite Control

    I am unable to do this because the properties don't exist
    at the time CreateChildControls() runs. I set the
    properties during the Page_Load of the parent.

    Is this an example of a time when I would need to use a
    superclassed control? I have never wrote one, but I am
    reading on them now. Still unclear how to resolve this
    issue.

    Thanks,

    Paul
    Paul Guest

  6. #5

    Default Re: Dynamically create non-fixed number of TextBoxes in Composite Control

    "Paul" <pajanisko@snopud.com> wrote in message
    news:045401c362b4$adbe48b0$a501280a@phx.gbl...
    > I am unable to do this because the properties don't exist
    > at the time CreateChildControls() runs. I set the
    > properties during the Page_Load of the parent.
    >
    > Is this an example of a time when I would need to use a
    > superclassed control? I have never wrote one, but I am
    > reading on them now. Still unclear how to resolve this
    > issue.
    Why is CreateChildControls running before Page_Load? That's almost certainly
    wrong.

    I had a control doing something like that due to EnsureChildControls calls
    at the wrong times. Removing them fixed the control.
    --
    John Saunders
    Internet Engineer
    [email]john.saunders@surfcontrol.com[/email]


    John Saunders Guest

  7. #6

    Default Re: Dynamically create non-fixed number of TextBoxes in Composite Control

    Sorry for the confusion, I was referring to Page_Load of
    the parent page which contains the control. If you
    follow through a debug, you can see the path.

    I found a fix!!! I was reading a book from Jeff Prosise
    called "Programming Microsoft .NET" and saw the light.
    On page 338 he explains how to dynamically load controls
    onto the page. I set asp:placeholders on the page where
    I want my control to be rendered, then did this in my
    code behind of the parent page:

    ArrayList myList = PJObject2.GetPJData();
    TestControl myTestControl = (TestControl) LoadControl
    ("TestControl.ascx");
    myTestControl.myList = myList;
    myTestControl.isPJObject2 = true;
    myTestControlPlaceHolder.Controls.Add(myTestContro l);

    In the control, TestControl.ascx, I was able to access
    the properties "myList" and "isPJObject2" in
    the "CreateChildControls" method.

    Thanks for the help,

    Paul

    Paul Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139