Passing ID to UserControl which builds dynamic textboxes

Discussion in 'ASP .Net Web Controls' started by Col, Apr 27, 2004.

  1. Col

    Col Guest

    Hi Guys

    I've been having some fun with the following, and hopefully someone
    can help out:

    I have a UserControl used to display customised Address Fields. The
    address fields are just textboxes which are built up dynamically from
    values in a table in my database.

    The user control queries the database depending on an ID and then
    builds these textboxes up. Now, to maintain the state of the textboxes
    through postbacks, I was told to put the Dynamic code into the
    Page_Init sub in the User Control. This all works fine and the fields
    keep state on all my postbacks.

    My problem is that I need to pass an ID to the query in the Page_Init
    sub in the user control, so that query pulls out the relevant records
    only. I can do this through a Public property in the usercontrol
    class, but the Page_Init sub in the user control fires before i can
    pass anything into it from my Page.

    Does anyone know how I can pass this ID into my user control before
    the Page_Init sub fires?

    AFTER that failed... I moved my Dynamic Code in the User Control from
    the Page_Init to the Page_Load sub and have been able to pass my ID to
    the user control from my Page with success. And the state is also kept
    intact. But now, when I try iterate through the "user control's"
    controls to get their values, the Page isnt aware of any child
    controls belonging to my Placeholder Control in the user control. I
    spose its because they havent been Initialised in Page_Init. (this
    part does work if the code is in Page_Init though, but then i have the
    first problem mentioned)

    Does anyone know what I can do to get either of these methods working?

    Thanks alot
    Col
     
    Col, Apr 27, 2004
    #1
    1. Advertisements

  2. Col

    Jonathan V Guest

    Have you re-initialized your user control on each post-back, sounds like
    that has not happened, and have you given the dynamically added usercontrols
    the same UserIDs as when they we first created.
    "Col" <> wrote in message
    news:...
    > Hi Guys
    >
    > I've been having some fun with the following, and hopefully someone
    > can help out:
    >
    > I have a UserControl used to display customised Address Fields. The
    > address fields are just textboxes which are built up dynamically from
    > values in a table in my database.
    >
    > The user control queries the database depending on an ID and then
    > builds these textboxes up. Now, to maintain the state of the textboxes
    > through postbacks, I was told to put the Dynamic code into the
    > Page_Init sub in the User Control. This all works fine and the fields
    > keep state on all my postbacks.
    >
    > My problem is that I need to pass an ID to the query in the Page_Init
    > sub in the user control, so that query pulls out the relevant records
    > only. I can do this through a Public property in the usercontrol
    > class, but the Page_Init sub in the user control fires before i can
    > pass anything into it from my Page.
    >
    > Does anyone know how I can pass this ID into my user control before
    > the Page_Init sub fires?
    >
    > AFTER that failed... I moved my Dynamic Code in the User Control from
    > the Page_Init to the Page_Load sub and have been able to pass my ID to
    > the user control from my Page with success. And the state is also kept
    > intact. But now, when I try iterate through the "user control's"
    > controls to get their values, the Page isnt aware of any child
    > controls belonging to my Placeholder Control in the user control. I
    > spose its because they havent been Initialised in Page_Init. (this
    > part does work if the code is in Page_Init though, but then i have the
    > first problem mentioned)
    >
    > Does anyone know what I can do to get either of these methods working?
    >
    > Thanks alot
    > Col
     
    Jonathan V, Apr 27, 2004
    #2
    1. Advertisements

  3. Hi Col,

    Can you post a very short sample of the code you're using in order to better
    illustrate the problem?

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx
    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup

    "Col" <> wrote in message
    news:...
    > Hi Guys
    >
    > I've been having some fun with the following, and hopefully someone
    > can help out:
    >
    > I have a UserControl used to display customised Address Fields. The
    > address fields are just textboxes which are built up dynamically from
    > values in a table in my database.
    >
    > The user control queries the database depending on an ID and then
    > builds these textboxes up. Now, to maintain the state of the textboxes
    > through postbacks, I was told to put the Dynamic code into the
    > Page_Init sub in the User Control. This all works fine and the fields
    > keep state on all my postbacks.
    >
    > My problem is that I need to pass an ID to the query in the Page_Init
    > sub in the user control, so that query pulls out the relevant records
    > only. I can do this through a Public property in the usercontrol
    > class, but the Page_Init sub in the user control fires before i can
    > pass anything into it from my Page.
    >
    > Does anyone know how I can pass this ID into my user control before
    > the Page_Init sub fires?
    >
    > AFTER that failed... I moved my Dynamic Code in the User Control from
    > the Page_Init to the Page_Load sub and have been able to pass my ID to
    > the user control from my Page with success. And the state is also kept
    > intact. But now, when I try iterate through the "user control's"
    > controls to get their values, the Page isnt aware of any child
    > controls belonging to my Placeholder Control in the user control. I
    > spose its because they havent been Initialised in Page_Init. (this
    > part does work if the code is in Page_Init though, but then i have the
    > first problem mentioned)
    >
    > Does anyone know what I can do to get either of these methods working?
    >
    > Thanks alot
    > Col
     
    Victor Garcia Aprea [MVP], Apr 28, 2004
    #3
  4. Col

    Col Guest

    Hi Jonathan

    Thanks very much for getting back to me.
    I figured out part of the problem lastnight.
    It all comes down to the order of specific events and when they were
    firing. I kept my dynamic usercontrol code in the Page_load, but when
    I tried to loop through the controls (and got no child controls), I
    was doing it in the Page_load of the Page itself, which fired before
    the usercontrol even built up dynamic the controls. Therefor, they
    didnt exist. Doh! I moved the 'looping through controls' code into any
    other event which occured after the page_load and all worked fine.
    If only I thought of putting the tracing on BEFORE pulling all my hair
    out.

    Thanks again.
    Regards,
    Colin
     
    Col, Apr 28, 2004
    #4
    1. Advertisements

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. Brian Pittman

    Dynamic TextBoxes

    Brian Pittman, Nov 13, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    467
    Anatoly
    Nov 13, 2003
  2. Michael Meckelein

    dynamic html table with textboxes

    Michael Meckelein, Apr 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,068
    Michael Meckelein
    Apr 14, 2004
  3. =?Utf-8?B?Qm9vbmFhcA==?=

    dynamic webform - repeat textboxes

    =?Utf-8?B?Qm9vbmFhcA==?=, Mar 21, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    450
    Karl Seguin
    Mar 21, 2005
  4. Angel.Net
    Replies:
    1
    Views:
    432
    =?Utf-8?B?Q3JhaWc=?=
    Jun 15, 2005
  5. =?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=

    Dynamic Textboxes

    =?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=, Sep 9, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,764
    =?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=
    Sep 9, 2005
  6. theresa
    Replies:
    1
    Views:
    657
    =?Utf-8?B?bXVzb3NkZXY=?=
    Jun 26, 2006
  7. begin22

    array of textboxes- dynamic controls

    begin22, Apr 22, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    427
    begin22
    Apr 22, 2007
  8. \A_Michigan_User\
    Replies:
    4
    Views:
    359
    Thomas 'PointedEars' Lahn
    Nov 16, 2007
Loading...