Problem with dinamically created controls

Discussion in 'ASP .Net' started by Rafi, Dec 1, 2003.

  1. Rafi

    Rafi Guest

    Hi,

    In my database I have table category where I store diffrent categories and
    subcategories. I decied to create LinkButtons dinamically with assigned name
    of category and its id. I also implemented an event onClick which task is to
    create LinkButton subcategories.

    When the page is loaded main categories are displayed, when I click on any
    of that buttons a subcategories will appear on the screen.

    The problem is, when I click on subcategory LinkButton.
    All subcategories disappear and only LinkButtons with main categories remain
    on the page.

    What is wrong?

    private void Page_Load(object sender, System.EventArgs e)
    {
    SqlDataReader dr;

    KategorieGlowneProc.Connection.Open(); // stored procedure to get main
    categories
    dr = KategorieGlowneProc.ExecuteReader();
    while ( dr.Read() )
    {
    LinkButton button = new LinkButton();
    button.Attributes.Add("runat","server");
    button.ID = dr.GetValue(0).ToString();
    button.Text = dr.GetValue(2).ToString();
    button.Click += new System.EventHandler(podkategoria);
    Page.Controls[1].Controls.Add(button);
    Page.Controls[1].Controls.Add(new LiteralControl("<br>"));
    }

    dr.Close();
    KategorieGlowneProc.Connection.Close();
    }

    private void podkategoria(object sender, System.EventArgs e)
    {
    LinkButton przycisk = (LinkButton)sender;
    SqlDataReader dr;
    PodkategorieProc.Parameters["@id_kategorii"].Value = przycisk.ID; //
    stored procedure to retrive subcategories
    PodkategorieProc.Connection.Open();
    dr = PodkategorieProc.ExecuteReader();
    while( dr.Read() )
    {
    LinkButton button = new LinkButton();
    button.Attributes.Add("runat","server");
    button.ID = dr.GetValue(0).ToString();
    button.Text = dr.GetValue(2).ToString();
    button.Click += new System.EventHandler(podkategoria);
    Page.Controls[1].Controls.Add(new LiteralControl("<br>"));
    Page.Controls[1].Controls.Add(button);
    }

    dr.Close();
    PodkategorieProc.Connection.Close();
    }


    Thanks for help

    Rafi
     
    Rafi, Dec 1, 2003
    #1
    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. Leonardo Gangemi
    Replies:
    0
    Views:
    326
    Leonardo Gangemi
    Apr 7, 2004
  2. =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?=

    Dinamically created webcontrol does not fire events

    =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?=, May 24, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    396
    =?Utf-8?B?Sm9yZ2UgUmliZWlybw==?=
    May 25, 2007
  3. Fabiano

    How to read listbox values created dinamically

    Fabiano, Jun 25, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    127
    Fabiano
    Jun 25, 2004
  4. Replies:
    0
    Views:
    117
  5. Replies:
    2
    Views:
    93
Loading...

Share This Page