Many ascx.cs ascx-to-one errors in VS2008

I am developing a second language support for the site. So I made duplicate .ascx and .aspx files for existing ascx.cs and aspx.cs

In most cases, everything works fine .. but suddenly I get:

The type 'ctrl_xxx' exists both in 'c: \ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ Temporary ASP.NET files \ d072cc72 \ b9d5698b \ App_Web_xdmblegv.dll' and in 'c: \ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ Temporary ASP.NET files \ d072cc72 \ b9d5698b \ App_Web_gkptrzo2.dll '(translated from English)

ctrl_xxx ctrl = (ctrl_xxx) LoadControl("xxx.ascx"); 

I have few such lines of code ... and the same error occurs with one of them. But WITHOUT any changes from me with these files. To fix thaat error for some time, I need to delete the solution folder and the website folder and rewrite them from SS. Maybe a problem with the solution? The solution was converted from vs2005.

+4
source share
3 answers

You should not localize an asp.net site by duplicating pages or controls. You use, for example, language-specific resource files that are referenced by a single page or control. Check out this one for a start on how to localize asp.net websites.

+3
source

I agree with @Joe R, copying code is not a good way to localize. You may feel that you have gone too far along this path to change your approach, but in the end you will be much happier and more productive with a different solution.

At a minimum, I would switch to a different approach for the rest of the localization, complete the project, and then come back later and convert what you already did with the new method.

Take a look at the following:

+2
source

If you need to quickly fix the problem, you will need to provide new names on all the pages and controls that you copied. The error occurs due to the presence of two user controls with the same name (exactly the same as said).

However, everyone else is true that you are doing it wrong. What happens when you need to change some code? This will cause additional maintenance because you need to make changes in two places. Most likely, you will forget it, and you will end up spending a lot of time. If you invest in using language resource files now, you can save on headaches later. And I don’t even mention the possibility of adding an additional language on the road.

Edit

Try the following if you still do not want to use language resource files.

  • Put the non-language specific code in a separate .cs file. Make sure it inherits from System.Web.UI.UserControl
  • In ASCX 1, make sure the ascx.cs class inherits from your class created in step 1.
  • In ASCX 2, make sure its ascx.cs class inherits from your class created in step 2.
+1
source

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


All Articles