Click here to Skip to main content
15,900,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi every body, some one can help me??
I make a web application with c# but my problem is with affecting event to a Link Button not inside load function
it doesn't work

this is my code
the control is AN
and the function is AN_Click

protected void NewTache_Click1(object sender, ImageClickEventArgs e)
    {
        Session["TableNonPrevu"] = Int32.Parse(Session["TableNonPrevu"].ToString()) + Int32.Parse(TextBox43.Text);
        for (Int32 i = 0; i < Int32.Parse(Session["TableNonPrevu"].ToString()); i++)
        {
            Int32 currentrow=i + Table2.Rows.Count;
            TableRow newrow = new TableRow();
            newrow.Cells.Add(new TableCell());
            newrow.Cells.Add(new TableCell());
            newrow.Cells.Add(new TableCell());
            newrow.Cells.Add(new TableCell());            
            TextBox tache = new TextBox();            
            TextBox charge = new TextBox();
            TextBox description = new TextBox();
            ListBox responsable = new ListBox();
            LinkButton AN = new LinkButton();
            UpdatePanel ANU = new UpdatePanel(); 
            tache.Width = 347;            
            responsable.Width = 74;
            responsable.Height = 26;            
            responsable.ID = "re" + currentrow;
            AN.ID = "AN" + currentrow;
            AN.Text = " +";
            AN.OnClientClick = "Ressource()";
            AN.Click += new EventHandler(AN_Click);
            ANU.ID = "AN"+ currentrow +"U";
            AN.CommandArgument = "2:" + currentrow + ":" + responsable.ID +":"+ ANU.ID;
            charge.Width = 75;
            description.Width = 347;
            ANU.ContentTemplateContainer.Controls.Add(responsable);
            ANU.ContentTemplateContainer.Controls.Add(AN);
            ANU.UpdateMode = UpdatePanelUpdateMode.Conditional;
            newrow.Cells[0].Controls.Add(tache);
            newrow.Cells[1].Controls.Add(ANU);
            newrow.Cells[1].HorizontalAlign = HorizontalAlign.Left ;
            newrow.Cells[2].Controls.Add(charge);
            newrow.Cells[3].Controls.Add(description);
            Table2.Rows.Add(newrow);
        }
        NonPrevue.Update();
    }

thank's :doh:
Posted
Comments
[no name] 12-Jul-10 17:50pm    
Reason for my vote of 1
Rejected proper answers

When controls are created dynamically they must be recreated during the postback in order for the event to be triggered.
 
Share this answer
 
Comments
achekraali 1-Jul-10 6:41am    
thanks for your answer
but in the first click we can't create controls dynamically because the postback is triggered before the click event
[no name] 1-Jul-10 7:40am    
Learn your ASP.NET page lifecycle. Dynamic controls should be created in the PreInit event which occurs before control events are processed.
achekraali 1-Jul-10 9:49am    
I know that ,do you have an other solution??
achekraali 2-Jul-10 4:27am    
Reason for my vote of 1
this is not a good answer
VB
If the linkbutton has PostBackUrl set then the Click event of that linkbutton will not fire.
 
Share this answer
 
Comments
achekraali 1-Jul-10 6:43am    
no i don't want to refresh currently page
achekraali 2-Jul-10 4:26am    
Reason for my vote of 1
not a professional answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900