locked
Problem Loading a Custom Control RRS feed

  • Question

  • User-1901062142 posted

    Hi Everyone,

    I wanted to load a custom control in to a User Control.

    public EmailTemplate(string templateLocation)

    {
    Page p = new Page();
    _template = (EmailTemplateBase)p.LoadControl(templateLocation);
    }

    I am passing template location as "~/MyEmailTemplate.ascx"; ( This user control is placed in the application root folder)

    I have used the some code in many projects and works.  When i try to load the custom control, It says "object reference not found".

    (_template in the above code snippet returns null).

    I believe the way i specify the "custom control" path is right.

    I am stuck with this for hours and hours. 

    I appreciate any suggestions to resolving this issue.

    Thank You, 

    Saturday, April 7, 2012 12:06 AM

Answers

  • User79986525 posted

    Hi udayr

    Before using the custom control on the page you have to register it .

    <%@ Register Src="~/Controls/LoginHeader.ascx" TagName="Login" TagPrefix="uc1" %>

    and then you can use it like this

     <uc1:Login ID="login2" runat="server" />

    on your aspx page .



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 7, 2012 2:53 AM

All replies

  • User79986525 posted

    Hi udayr

    Before using the custom control on the page you have to register it .

    <%@ Register Src="~/Controls/LoginHeader.ascx" TagName="Login" TagPrefix="uc1" %>

    and then you can use it like this

     <uc1:Login ID="login2" runat="server" />

    on your aspx page .



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 7, 2012 2:53 AM
  • User3866881 posted

    Hello udayr:)

    Before using this control,you should register it by dragging and dropping your own customized control onto the page to generate a statement of registering,and then do your codes to continue……

    Reguards!

    Sunday, April 8, 2012 10:03 PM