Many ascx-to-one ascx.cs bug in VS2008
I'm developing second language support for the site. So I made duplicate .ascx and .aspx files for existing ascx.cs and aspx.cs
Most of the time everything works fine.. but suddenly I'm getting:
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' (t开发者_开发技巧ranslated from russian)
ctrl_xxx ctrl = (ctrl_xxx) LoadControl("xxx.ascx");
I have few such strings of code... and same error occurs with one of them. But WITHOUT any changes from me with those files. To fix thaat bug for some time I need to delete solution and website folder and reget them from SS. Maybe there is an issue with solution? Solution was converted from vs2005.
You shouldn't localize an asp.net site by duplicating pages or controls. You use, for example, language specific resource files that are referenced in the one page or control. Have a look at this for a start on how to localize asp.net websites.
I agree with @Joe R, copying code is not a good way to localize. You may feel like you have gone too far down this road to change your approach, but in the long run you will be much happier and more productive with a different solution.
At the minimum I would switch to a different approach for the rest of the localization, finish the project, and then go back later and convert what you have already done to the new method.
Take a look at the following:
- Globalization and localization demystified in ASP.NET 2.0
- How do you localize a database driven website
If you need a quick fix for your problem, you'll need to give new names to all of the pages and controls you copied. The error comes from having two user controls with the same name (just like it says).
However, everyone else is correct in that you are going about this the wrong way. What happens when you need to change some code? It will cause extra maintenance because you need to make changes in two places. More than likely, you will forget one, and you'll end up wasting a lot of time. If you invest in using language resource files now, you'll save on headaches later. And, I'm not even mentioning the possibility of needing to add an additional language down the road.
Edit
Try the following if you still don't want to use language resource files.
- Put the non-language specific code into a separate .cs file. Make sure it inherits from
System.Web.UI.UserControl
- In ASCX 1, make sure its ascx.cs class inherits from your class you created in step 1.
- In ASCX 2, make sure its ascx.cs class inherits from your class you created in step 2.
精彩评论