If you are using Visual Studio, switch your page to Design View. From the Solutions Explorer window, drag and drop the control file onto your page, and it will automatically set the references for you.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Still not able to refer to the simple control in App_Code.
Every time have an error at run-time.
Error message - varied, depend on syntax used in Register directive.
Control code in App_Code folder:
public class DummyControl3 : System.Web.UI.WebControls.Label
{
const string LabelText = "This is a Dummy Label from App_Code folder.";
public DummyControl3() : base() { }
public override string Text { get { return LabelText; } }
}
Parser Error Message:
The base class includes the field 'Label2', but its type (OneFormWebApplication.CTRL3.DummyControl3) is not compatible with the type of control (OneFormWebApplication.CTRL3.DummyControl3).
Compiler Error Message:
CS0433: The type 'DummyControl3' exists in both 'App_Code.5whj1ddz, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'OneFormWebApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
Question still open - How to refer to the control in App_Code folder?
namespace WebApplication1.App_Code
{
public class DummyControl3 : System.Web.UI.WebControls.Label
{
const string LabelText = "This is a Dummy Label from App_Code folder.";
public DummyControl3() : base() { }
public override string Text { get { return LabelText; } }
}
}
result:
Best Regards,
Jenifer
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
None
0 Points
26 Posts
How do I refer to the Control?
Jul 12, 2019 03:10 PM|Andrey Belyakov|LINK
Hello folks,
I have an overloaded control.
Not much - just few properties adjusted to interact with my classes.
When control are in DLL - there are no problem:
< % @ Register TagPrefix="CTRL" Namespace="MyNamespace.Controls" Assembly="MyDllWithControls" % >
< CTRL:SitesDropDownList ID="sites" runat="server" > < / CTRL:SitesDropDownList >
and control available.
For quick modification I would like to have control on the same site - in App_Code folder.
How do I refer to this control?
Star
9859 Points
2557 Posts
Re: How do I refer to the Control?
Jul 12, 2019 03:53 PM|AZMatt|LINK
If you are using Visual Studio, switch your page to Design View. From the Solutions Explorer window, drag and drop the control file onto your page, and it will automatically set the references for you.
Contributor
2100 Points
705 Posts
Re: How do I refer to the Control?
Jul 15, 2019 06:36 AM|Jenifer Jiang|LINK
Hi Andrey Belyakov,
According to your description, I'm sorry that I'm not so clear about your issue.
You say that the control is in DLL.
In that case, you just have to register the control with the three attributes: Assembly, Namespace, TagPrefix.
As long as your folder, your page file and the dll are in the same project, you could refer to the control in the same way.
Reference: https://support.microsoft.com/en-us/help/321749/how-to-register-an-assembly-in-a-webform-to-use-a-custom-control
Best Regards,
Jenifer
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
None
0 Points
26 Posts
Re: How do I refer to the Control?
Jul 15, 2019 07:58 AM|Andrey Belyakov|LINK
You say that the control is in DLL.
-----
I sad that I do not have problem to refer to the control when control are in DLL.
Question is - If I remove DLL from the project and put control code into App_Code folder - How do I refer to the control in App_Code folder?
None
0 Points
26 Posts
Re: How do I refer to the Control?
Jul 15, 2019 08:01 AM|Andrey Belyakov|LINK
> switch your page to Design View.
Sorry, my Studio didn't switch into Design View after few crash and fixing.
Where and what will be written after those manipulation?
Contributor
2100 Points
705 Posts
Re: How do I refer to the Control?
Jul 15, 2019 09:42 AM|Jenifer Jiang|LINK
Hi Andrey Belyakov,
You may do the following steps:
For more, you could refer to this link which contains the more detailed description: https://stackoverflow.com/a/4605805/10487763
Best Regards,
Jenifer
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
None
0 Points
26 Posts
Re: How do I refer to the Control?
Jul 15, 2019 02:15 PM|Andrey Belyakov|LINK
<%@ Register Namespace="CustomControls" Assembly="__code" tagprefix="CTRL" %>
-----
This was an initial cause of the question - already try this and it didn't work.
Even if I wrap control code in namespace or remove 'CustomControls' (to "") or replace namespace from class - didn't work - control not found.
Any specific configuration for IIS 7.0 or IIS 10.0 Express or Studio to have this working?
OR
What need to be placed as Namespace and Assembly?
None
0 Points
26 Posts
Re: How do I refer to the Control?
Jul 15, 2019 03:14 PM|Andrey Belyakov|LINK
Ohhh, didn't see the link. Will check tomorrow. Thanks.
None
0 Points
26 Posts
Re: How do I refer to the Control?
Jul 24, 2019 09:41 AM|Andrey Belyakov|LINK
Still not able to refer to the simple control in App_Code.
Every time have an error at run-time.
Error message - varied, depend on syntax used in Register directive.
Control code in App_Code folder:
Registration
Parser Error Message: The base class includes the field 'Label2', but its type (OneFormWebApplication.CTRL3.DummyControl3) is not compatible with the type of control (OneFormWebApplication.CTRL3.DummyControl3).
Registration:
Parser Error Message: The file '/App_Code/DummyControl3.cs' is in the special directory 'App_Code', which is not allowed.
Registration :
Compiler Error Message: CS0433: The type 'DummyControl3' exists in both 'App_Code.5whj1ddz, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'OneFormWebApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
Question still open - How to refer to the control in App_Code folder?
Contributor
2100 Points
705 Posts
Re: How do I refer to the Control?
Jul 25, 2019 06:40 AM|Jenifer Jiang|LINK
Hi Andrey Belyakov,
I've tried your code and it seems work well. You may try to move the Inherits as below.
TestControl.aspx
<%@ Register tagPrefix ="CTRL" namespace="WebApplication1.App_Code" Assembly="__code" %> <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestControl.aspx.cs" Inherits="WebApplication1.TestControl" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <CTRL:DummyControl3 ID="sites" runat="server" > </CTRL:DummyControl3> </div> </form> </body> </html>
DummyControl3.cs in App_Code
result:
Best Regards,
Jenifer
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.