.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 - Reset the Admin Password via SQL Server

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

Umbraco Macro for IFrame when Embedding Video, Vimeo Universal Player, or other types of IFrame on to a Page XSLT version and Razor Version