User control "Link" in web.config?

I am trying to instantiate a user control programmatically in the code menu of a website *. The only ways I found the link to the user control class were:

  • Register the control in the web.config file and delete the control on the page (it works, but I do not want the control on the page as I want to dynamically add it).
  • Add the link <% @Reference Control = "Name.aspx"> to the aspx page at the top.

Ideally, I would like to have a link to an aspx page for the link without placing the <% @Reference> ad at the top of each page. I know that I can "register" controls in the web.config file, so I don’t need to do this on every page, so I wonder if something like this exists for links. I am pretty sure that I have something missing in the whole concept of registration / link, so maybe just an explanation that the best way to do this is ok.

* A project such as a website, not a web application, if that matters.

+4
source share
1 answer

There is some relevant discussion of this problem in the comments: http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls- in-web-config.aspx

In my experience, confirmed by this thread, programmatic access to user controls is painful in general in a website design. If you create an instance of dynamic control, I think this reinforces the use case of a web application project, so you don't need @Reference.

Reflection can be one way around this if you are desperate; you can start here: http://geekswithblogs.net/aghausman/archive/2009/04/15/how-to-pass-parameters-to-the-dynamically-added-user-control.aspx

+1
source

Source: https://habr.com/ru/post/1314965/


All Articles