Kiwimoisi
Kiwimoisi

Reputation: 4182

Linkbutton Dynamically Click

I have a problem with my project . I am creating link buttons dynamically to show the projects. When I click on a project it is firing and I can display link buttons of bugs dynamically . Now when I click on a bug , I want to display the description, dynamically too , but this click event is not firing , and I can't fix it .. This is my code .

private void LoadXmlBugs(XDocument xDocument)
    {
        //Load all bugs
        IEnumerable<Bugs> data = from query in xDocument.Descendants("bugs")
                                 where (((string)query.Element("bug_status") == "NEW") ||
                                 ((string)query.Element("bug_status") == "REOPENED") ||
                                 ((string)query.Element("bug_status") == "New"))
                                 select new Bugs
                                 {
                                     Bug_Id = (string)query.Element("bug_id"),
                                     Short_Desc = (string)query.Element("short_desc"),
                                     Bug_Status = (string)query.Element("bug_status"),
                                     Priority = (string)query.Element("priority"),
                                     Creation_Ts = (string)query.Element("creation_ts"),
                                 };

        Bugs = new List<Bugs>(data);
        string statut = Request.QueryString.Get("bug_status");

        foreach (Bugs b in Bugs)
        {

            System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
            img.ImageUrl = ("~/Img/FolderIco.png");
            PanelAllBugs.Controls.Add(img);
            LinkButton lkButtonBugs = new LinkButton();
            lkButtonBugs.Click += new EventHandler(lkButtonBugs_Click);
            lkButtonBugs.ID = b.Bug_Id;
            lkButtonBugs.Tag = b.Short_Desc;
            lkButtonBugs.Text = b.Bug_Status + "     " + b.Short_Desc + "      " + "<br>";
            lkButtonBugs.Attributes.Add("runat", "server");
            PanelAllBugs.Controls.Add(lkButtonBugs);

        }
    }


void lkButtonBugs_Click(object sender, EventArgs e)
    {
        bugId = ((sender as LinkButton).ID);

        LoadTheDescriptionForABug(bugId, ((sender as LinkButton).ID));
        LoadBugsComments();
        LoadBugsAttachments();
    }

Can someone help me ?

Thank you very much .

Upvotes: 1

Views: 262

Answers (1)

Davide Piras
Davide Piras

Reputation: 44605

from where do you call the method: LoadXmlBugs ?

dynamically added controls should be added at every PostBack so everything depends on where/when you are calling the method above.

try to call LoadXmlBugs from the Page_Init event handler.

Upvotes: 2

Related Questions