Add a button dinamically
-
Is there any way of adding a button to a web page dinamically? Say, a button that when clicked creates another button in the page? I know this is possible in a Windows Form, but not sure about a ASP.NET page. Thanks in advance.
-
Is there any way of adding a button to a web page dinamically? Say, a button that when clicked creates another button in the page? I know this is possible in a Windows Form, but not sure about a ASP.NET page. Thanks in advance.
-
Is there any way of adding a button to a web page dinamically? Say, a button that when clicked creates another button in the page? I know this is possible in a Windows Form, but not sure about a ASP.NET page. Thanks in advance.
//In the ButtonClick event of the first button load the newbutton protected void Button1_Click(object sender, EventArgs e) { loadnewbutton = new Button(); loadnewbutton.Text = "NewButton"; loadnewbutton.ID = "newButton"; loadnewbutton.Click += new System.EventHandler(this.loadnewbutton_Click); this.PlaceHolder1.Controls.Add(loadnewbutton); } protected void loadnewbutton_Click(object sender, EventArgs e) { Response.Write("HEllo"); }
Koushik
-
//In the ButtonClick event of the first button load the newbutton protected void Button1_Click(object sender, EventArgs e) { loadnewbutton = new Button(); loadnewbutton.Text = "NewButton"; loadnewbutton.ID = "newButton"; loadnewbutton.Click += new System.EventHandler(this.loadnewbutton_Click); this.PlaceHolder1.Controls.Add(loadnewbutton); } protected void loadnewbutton_Click(object sender, EventArgs e) { Response.Write("HEllo"); }
Koushik
//Declare the loadnewbutton first. //I mean as follows. System.Web.UI.WebControls loadnewbutton = new Button();
Koushik
-
Is there any way of adding a button to a web page dinamically? Say, a button that when clicked creates another button in the page? I know this is possible in a Windows Form, but not sure about a ASP.NET page. Thanks in advance.
Just create an instance of the control you want and add it to the Controls collection of another control (a Panel or Placeholder is usually best). If you want user controls you can use the CreateUserControl method of the Page object. Note however that dynamic controls aren't persisted accross postbacks, you have to manage that yourself or check this out: DynamicControlsPlaceholder.aspx
-
Is there any way of adding a button to a web page dinamically? Say, a button that when clicked creates another button in the page? I know this is possible in a Windows Form, but not sure about a ASP.NET page. Thanks in advance.
Yes
Vasudevan Deepak Kumar Personal Homepage Tech Gossips