Add UserControl To Page From Another Class
- by Raika
I have page and call method inside my page. I want to add some control to my page Control (not page itself) inside that method.
namespace Program
{
public partail class Default : Page
{
protected void Page_Load(object sender, Eventargs e)
{
MyClass.Calling(this);
}
}
}
in another class
namespace Program
{
public class MyClass
{
public static void Calling(Page page)
{
Textbox txt = new Textbox()
// I want somthing like this.
// page.PlaceHolder1.Controls.Add(txt);
}
}
}
Is this possible?
My Default.aspx :
<%@ Page Title="Home Page" MasterPageFile="~/Site.master" ... %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</asp:Content>
Update:
thanks to The King for help. his suggest work correctly if control is inside page not Content of master page like my defualt sample code.