When trying to use the DnnUrlControl or old UrlControl in a custom module, I get the error below when setting the Url property
Message:Error rendering URLControl subcontrols.
StackTrace
InnerMessage:Object reference not set to an instance of an object.
InnerStackTrace: at DotNetNuke.UI.UserControls.UrlControl.DoChangeURL() at DotNetNuke.UI.UserControls.UrlControl.OnPreRender(EventArgs e)
ASCX File:
<portal:URL ID="dnnUrlCntr" runat="server" />
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
var locCtl = new CountyController();
ddlCounty.DataSource = locCtl.GetCounties().OrderBy(c => c.CountyName);
ddlCounty.DataTextField = "CountyName";
ddlCounty.DataValueField = "CountyId";
ddlCounty.DataBind();
ddlCounty.Items.Insert(0, new System.Web.UI.WebControls.ListItem("< Select County >", ""));
var tc = new ProgramController();
if (ProgramId > 0)
{
var t = tc.GetProgram(ProgramId);
if (t != null)
{
txtProgramName.Text = t.ProgramName;
dnnUrlCntr.Url = t.Url;
}
var plp = tc.GetProgramCountyPhoneListItems(ProgramId);
rptLocatonList.DataSource = plp;
rptLocatonList.DataBind();
}
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}