Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use user control in the same folder as the page

Tags:

I get this message at runtime of ASP.NET 2 page :

The page 'MyFolder/blabla.aspx' cannot use the user control 'MyFolder/MyControl.ascx', because it is registered in web.config and lives in the same directory as the page.

Of course I can separate them to 2 different folders and thus solve the problem, but the question is :

WTF !?!?! Why I can't put them in the same folder ?! Why can't they all .. get along !?! :)

Thanks

like image 830
Alex Avatar asked Jun 03 '10 08:06

Alex


People also ask

What is difference between page and Web user control?

ASP.NET Page can be viewed directly in the Browser. User Control cannot be viewed directly in the browser. User Controls are added to WebPages and you view them by requesting a web page in your browser. User Control does not have a HTML, Body or Form element.

How do I add a user control to a SharePoint Webpart?

In the list of SharePoint templates, choose User Control (Farm Solution Only). User controls work only in farm solutions. In the Name box, specify a name for the user control, and then choose the Add button.

Can we use user control in MVC?

In ASP.Net you need to register one tagprefix and then use the user control by tagprefix registered but in ASP.Net MVC using simple Thml. RenderPartial we can use the user control.


1 Answers

This limitation is by design due to an internal design consideration re: performance.

See here for further info.

Remarks

The TagPrefixInfo class allows you to programmatically access and modify tag-prefix information stored in a configuration file. It provides the same functionality as the ASP.NET @Register directive. Tag prefixes associate a "namespace" in ASP.NET to the assemblies and namespaces that must be included for custom controls and user controls to work properly. TagPrefixInfo objects are stored as members of a TagPrefixCollection object. The TagPrefixCollection class allows you to programmatically access and modify the controls subsection of the pages section of a configuration file.

TagPrefixInfo objects are added to the collection using the add element and specifying a value for the tagPrefix attribute along with values for other relevant attributes. The other required information varies based on the kind of control you will use with the specified tag prefix:

  • If it is a user control, you must define the TagPrefix, TagName, and Source properties.
  • If it is a custom control, you must define the TagPrefix, Namespace, and Assembly properties. The Assembly property is not required if the control is in the application code directory. The same tagPrefix value can be used to map to multiple assemblies or namespaces.

Note When a source is specified, the user control itself must not be in the same directory as the page. If it is, you get a run-time error when you attempt to load the page.

like image 196
codingbadger Avatar answered Oct 06 '22 05:10

codingbadger