Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi. I managed to create a button dynamically in a panel and assigned a function to fire when clicked. Ok i can see the button in the panel but when i click, function doesnt fire. (Actually button vanishes too.) This is the code:

Button eklemeButonu = new Button();
            eklemeButonu.Text = "Add";
            eklemeButonu.ID = "eklemeButonu";
            eklemeButonu.Attributes.Add("runat", "server");
            eklemeButonu.Click += EklemeButonu_Click;

Panel2.Controls.Add(eklemeButonu);



private void EklemeButonu_Click(object sender, EventArgs e)
       {
            //show message
       }


What I have tried:

put "runat server" attribute and some other attributes. but didnt work.
Posted
Updated 29-Jun-18 16:53pm
Comments
Afzaal Ahmad Zeeshan 27-Jun-18 19:48pm    
Can you check for any errors in the console window of the browser?

Dynamically generated controls should be recreated on each postbacks to retain them on the page. See:

ASP.Net Persist Dynamic Controls: Dynamic Controls disappear after PostBack in ASP.Net

Creating Dynamic Button LinkButton and ImageButton in ASP.Net
 
Share this answer
 
thank you for answers. i am better at windows forms so i won't use asp.
 
Share this answer
 
Comments
Richard Deeming 3-Jul-18 10:54am    
If you want to reply to a solution, click the "Have a Question or Comment?" button under that solution.

DO NOT post your reply as a new "solution".

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