UPDATED!
I've highlighted the line that throws the error and added the code-behind for one of my User Controls (its at the bottom).
I have the following method which allows me to dynamically add "user controls" via code behind.
Like this:
UserControl myCtrl = LoadControl( "/pathtocontrol/control.ascx", p1, p2 );
litControl.AddControl( myCtrl );
The LoadControl
method:
public static UserControl LoadControl(string UserControlPath, params object[] constructorParameters)
{
var p = new System.Web.UI.Page();
var ctl = p.LoadControl(UserControlPath) as System.Web.UI.UserControl;
if (ctl != null)
{
// Find the relevant constructor
System.Reflection.ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constructorParameters.Select(constParam => constParam == null ? "".GetType() : constParam.GetType()).ToArray());
//And then call the relevant constructor
if (constructor == null)
{
throw new MemberAccessException("The requested constructor was not found on : " + ctl.GetType().BaseType.ToString());
}
/***************************************************/
/***************************************************/
/******** THE ERROR IS THROWN AT THIS LINE! ********/
constructor.Invoke(ctl, constructorParameters);
/***************************************************/
/***************************************************/
}
// Finally return the fully initialized UC
return ctl;
}
Which when executed on a Godaddy Shared Hosting account (IIS 7.0) gives me System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Is there anyway to make this method work on a GoDaddy shared host?
Here is the code behind for one of my user controls:
using System;
using DM;
public partial class controls_CustomerSummaryLine : System.Web.UI.UserControl
{
public Customer Customer;
public bool Highlight;
public void Page_Load(object sender, EventArgs e)
{
}
public controls_CustomerSummaryLine()
{
}
public controls_CustomerSummaryLine(Customer customer)
{
Customer = customer;
}
public controls_CustomerSummaryLine(Customer customer, bool highlight)
{
Customer = customer;
Highlight = highlight;
}
}