Creating Controls

Discussion in 'ASP .Net Web Controls' started by Mike Towle, Apr 14, 2004.

  1. Mike Towle

    Mike Towle Guest

    Trying to create controls in a button.click event, not the Page_Init event. All examples of code I have found so far creates the controls and binds them to their container (form, placeholder, etc) in the Page_Init event. But if I try to create and bind a control in the button.click event, when the page refreshes I cannot remove / destroy the control. And if I reuse a dropdownlist control that was dynamically created in the button.click event then I cannot clear the list of items at all either. All I can do is add to the items collection. Cannot destroy the control and start over or clear the list of items. I am creating different controls based on values in a database. The button.click event destroys any previously created controls, fetches the next record in the database, creates the control based on the values in the database, binds it to the form or placeholder, and sets the properties of the control. Another issue is that if I dynamically create a control in the button.click event and bind it to a container such as a form or placeholder then if I query the container's controls.count method then the count has not changed!
     
    Mike Towle, Apr 14, 2004
    #1
    1. Advertising

  2. cross posts will least likely end up with answered questions.

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/27cok
    "Mike Towle" <> wrote in message
    news:...
    > Trying to create controls in a button.click event, not the Page_Init
    > event. All examples of code I have found so far creates the controls and
    > binds them to their container (form, placeholder, etc) in the Page_Init
    > event. But if I try to create and bind a control in the button.click
    > event, when the page refreshes I cannot remove / destroy the control. And
    > if I reuse a dropdownlist control that was dynamically created in the
    > button.click event then I cannot clear the list of items at all either.
    > All I can do is add to the items collection. Cannot destroy the control
    > and start over or clear the list of items. I am creating different
    > controls based on values in a database. The button.click event destroys
    > any previously created controls, fetches the next record in the database,
    > creates the control based on the values in the database, binds it to the
    > form or placeholder, and sets the properties of the control. Another
    > issue is that if I dynamically create a control in the button.click event
    > and bind it to a container such as a form or placeholder then if I query
    > the container's controls.count method then the count has not changed!
     
    Alvin Bruney [MVP], Apr 16, 2004
    #2
    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. Tarang Deshpande

    Creating Form Controls at Run-Time

    Tarang Deshpande, Jul 24, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    457
    Natty Gur
    Jul 25, 2003
  2. Ravi Ambros Wallau
    Replies:
    0
    Views:
    4,118
    Ravi Ambros Wallau
    Jun 1, 2005
  3. Tarscher
    Replies:
    9
    Views:
    423
    Russell
    Feb 13, 2007
  4. Nathan Sokalski
    Replies:
    4
    Views:
    1,169
    Muhammad Naveed Yaseen
    Sep 5, 2007
  5. Ravi Ambros Wallau
    Replies:
    0
    Views:
    329
    Ravi Ambros Wallau
    Jun 1, 2005
Loading...

Share This Page