none
How do I use the user control dynamically in master page? RRS feed

  • Question

  • ı have a master page, index.aspx and makale.ascx

    click on the buttons in masterpage I want to add a new user control in index.aspx page

     

    Tuesday, May 28, 2013 8:52 AM

Answers

  • 1. Add a PlaceHolder on the aspx page:

    <asp:PlaceHolder ID="container" runat="server" />

    2. Use the FindControl method on the ContentPlaceHolder in the MasterPage to find the PlaceHolder and add an instance of your UserControl it it:

    protected void MasterPageButton_Click(object sender, EventArgs e)
    {
        PlaceHolder container = (PlaceHolder)ContentPlaceHolder1.FindControl("container");
        if (container != null)
        {
            YourUserControl control = (YourUserControl)LoadControl("~/Controls/control.ascx");
            container.Controls.Add(control);
        }
    }

    Tuesday, May 28, 2013 10:47 AM