.Net Dynamicaly Create and Remove a Control / Object, such as a button. Web

    private void CreateControls()
    {
        // Create a New Button
        Button myButton = new Button();
        // Give the Button Some Properties
        myButton.Text = "A Dynamicaly Created Button";
        // Add Button to PlaceHolder
        // ** NOTE: The Planel must Exist in your design view
        Panel1.Controls.Add(myButton);
     
        }



    private void RemoveButton()
    {
        // Search for the button in the Page Controls Collection
        Button foundButton = (Button)Page.FindControl("myButton");

        // Remove the Button
        if (foundButton != null)
        {
            foundButton.Parent.Controls.Remove(foundButton);
        }
    }

Comments

Popular posts from this blog

Umbraco Razor Sort Nodes Ascending or Descending

Umbraco Razor get Querystring

Create a .NET Contact Form that Gets the Last Url Visited in C# Can also be Used in Umbraco