Click here to Skip to main content
15,914,481 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i want to create link buttons dynamically in my asp.net project.
pls help me in this regards..
how to create them n where to define events for them?
Posted
Comments
leonidasvijay 19-Aug-11 3:17am    
Please first search such non sense question on the google.
U will definitely get the answer.

1 solution

You can find examples on google for this. This is how your code would look like if you are adding a button:

C#
Button button = new Button();
// Set properties here
button.Click += new EventHandler(ClickEventHandlerName);

// You can also use any other container instead of directly adding to page
Page.Controls.Add(button);


Dynamic controls should be added in PreRender.
 
Share this answer
 
Comments
Sachin gulati 19-Aug-11 3:30am    
how to add control on some particular location??

and is this code appropriate?

private void Page_Load(object sender, System.EventArgs e)
{
RecreatePersistedControls();
}
private void Button_Click(object sender, System.EventArgs e)
{
CreateControl("newControl");
PersistControl("newControl");
}
private void RecreatePersistedControls()
{
// Call CreateControl for each persisted control
}
private void CreateControl(string id)
{
// Create controll with specified id,
// add it to controls collection, attach event handlers
}
private void PersistControl(string id)
{
// Persist specified id (in session for example)
}

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