Click here to Skip to main content
15,920,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends!

I generated button on panel from another buttonclick event.
now my both button are come together at same place i want button in diffrent location on panel in good manner how can i do it?

Is there any control, so button will set automatically when i create it?

my code is here:
C#
Button editbtn = new Button();
           editbtn.Text = "EDIT";

           Button delbtn = new Button();
           delbtn.Text = "Delete";



           panel1.Controls.Add(delbtn);
           panel1.Controls.Add(editbtn);
Posted
Updated 20-Nov-13 6:25am
v2
Comments
Sergey Alexandrovich Kryukov 20-Nov-13 14:47pm    
Why? Are you using absolute positioning? Is so, why?
Is it really ASP.NET, or this tag is a mistake? :-)
—SA

Give your buttons an ID or set the CSSClass property and use CSS.

Button editbtn = new Button();
           editbtn.Text = "EDIT";
           editbtn.ID = "EditButton";

           Button delbtn = new Button();
           delbtn.Text = "Delete";
           delbtn.ID = "DeleteButton";


           panel1.Controls.Add(delbtn);
           panel1.Controls.Add(editbtn);

In your css file
#EditButton
{
    CSS to position control
}
#DeleteButton
{
    CSS to position control
}
 
Share this answer
 
You have to know where on the Panel you wish to put your run-time created Buttons, and, depending on where you want to place them, you may need to utilize the dimensions of the Buttons.

For example:
C#
panel1.Controls.Add(delbtn);

panel1.Controls.Add(editbtn);

// position delbtn in absolute co-ordinates of its host Panel
delbtn.Location = new Point(20,10);

// position editbtn so its right edge is 8 pixels right of delbtn's right edge, and at the same vertical position as delbtn
editbtn.Location = new Point(delbtn.Right + 8, delBtn.Height);
 
Share this 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