1
votes

I am trying to add a user control dynamically in another user control but getting error message "The file '/controls/request_inspector.ascx' does not exist."

I added a reference to the control in the .aspx page that will use it, like this:

   <%@ Reference Control="request-inspector.ascx" %>

And in the UserControl I added a ClassName like this:

   <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="request-inspector.ascx.vb" 
       Inherits="Web.PO.request_inspector" ClassName="request_inspector" %>

Page Load event

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim c As request_inspector
    c = CType(LoadControl("~/controls/request_inspector.ascx"), request_inspector)
    c.ID = "c1"

    phReqInspectors.Controls.Add(c)
    c = Nothing
  End Sub

User Control is in the controls folder and i have tried changing the path but still the same error message. Here is the full path C:\Projects\PSource\projects\POProject\Web.PO\controls\request-inspector.ascx

1

1 Answers

0
votes

After removing the @Reference tag and the class name , it is workign fine but it doesn't make any sense. It might be Team Foundation server playing up as i added a new file in the project.

After that i tested with reference tag and it works fine.

    Dim c As request_inspector
    c = CType(LoadControl("~/controls/request-inspector.ascx"), request_inspector)
    c.ID = "c1"

    phReqInspectors.Controls.Add(c)
    c = Nothing

What difference would it make if i use a @Reference tag? I know that You use the @ Reference when you intend to load the control programmatically but what if i don't use it?