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. Advertising

  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. Advertising

  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. 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. Bill Green

    Suddenly aspnet_wp.exe memory builds up

    Bill Green, Jan 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    334
    Alvin Bruney
    Jan 19, 2004
  2. Frank Oquendo

    Automated builds?

    Frank Oquendo, Jan 22, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    337
    Scott Allen
    Jan 22, 2004
  3. Simon Harris

    VS.Net - Debug and Release Builds

    Simon Harris, Oct 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    384
    Steve C. Orr [MVP, MCSD]
    Oct 6, 2004
  4. Angel.Net
    Replies:
    1
    Views:
    358
    =?Utf-8?B?Q3JhaWc=?=
    Jun 15, 2005
  5. \A_Michigan_User\
    Replies:
    4
    Views:
    149
    Thomas 'PointedEars' Lahn
    Nov 16, 2007
Loading...

Share This Page