views:

123

answers:

3

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_car' exists both in 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\rzhdengine\d072cc72\b9d5698b\App_Web_xdmblegv.dll', and in 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\rzhdengine\d072cc72\b9d5698b\App_Web_gkptrzo2.dll' (translated from russian)

ctrl_car ctrl = (ctrl_car) LoadControl("car.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.

+2  A: 

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.

Joe R
Firstly, I have no time to change chosen approach.Secondly, I don't like such "official" approach for some reasons.
pukipuki
I'm not recommending it because it's offical, just because it will work. :) It's worth going down the resource file route as it isn't that slow...
Joe R
I'm using "official" just as a label for approach. What a slow issues you are talking about?
pukipuki
I'm saying that using resource files for localization is quite quick. You shouldn't find it difficult to copy your localized strings into resource files and reference them in the page you want to localize - e.g. Text="<%$ Resources:GlobalResources, Customer %>">
Joe R
Making copies much faster than making res-files and making ascx-files full of garbage like <%$ Resources:GlobalResources, Customer %> and thereby unreadable.
pukipuki
If you don't like Text=<%$ Resources:GlobalResources, Customer %> you can set the text in the code behind. Anyway, I think you'll find it better than trying to copy ascx files - at least it will work.
Joe R
ufff... I want to see text where it should be: in the ascx\aspx files. And this is completely eligible approach. Switching doesn't make sense. Java or PHP specialist also can said "convert on java\php - it will be easier or at least it will work" ))
pukipuki
Your approach may work eventually, but it has the potential of maintenance nightmares. Also, I'm sure if you convert to Java or PHP, you'll end up using more time than if you just did it the correct way in ASP.NET. Besides, the language resource file method for localization is not just an ASP.NET method. Generally speaking you'll use a similar (if not the same) method in any language.
Chris Dwyer
Eventually? Two instances of one class (same .cs) with different html should work fine eventually?)) Nice complement for Microsoft )
pukipuki
I was being nice. What you are doing is completely non-standard, and the main reason is that there is a better (quicker, less-maintenance) way of doing it. No technology is beholden to how you want to use it. Whether it is ASP.NET, Java, PHP, or whatever, there are ways of accomplishing localization. Just because you want to do it one way doesn't mean it's a bad technology if it doesn't work.
Chris Dwyer
+1  A: 

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:

Dana Holt
There is no copy of CODE ) many designs for one cs file. This is exactly NOT a DATABASE DRIVEN website )
pukipuki
@pukipuki - Look, you came here for advice and got it. It's up to you whether you want to take it or not - no need to argue about it.
Dana Holt
If so - why there is an add_comment feature?)
pukipuki
A: 

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.

  1. Put the non-language specific code into a separate .cs file. Make sure it inherits from System.Web.UI.UserControl
  2. In ASCX 1, make sure its ascx.cs class inherits from your class you created in step 1.
  3. In ASCX 2, make sure its ascx.cs class inherits from your class you created in step 2.
Chris Dwyer
Error comes from the bug. Many ascx to one ascx.cs - eligible approach....
pukipuki
Ok, I think I'm clearer on the situation. I've never heard of anyone doing what you're trying to do. ASP.NET was designed to have one code-behind (.cs) class per page. You can have those code-behind classes inherit from another class if you want, but it is a one-to-one relationship between an aspx file and aspx.cs. If you have a link to an example where someone has done what you're trying to do, by all means, post it and I'll stand corrected.
Chris Dwyer
See my edit above if you still want to pursue this method for localization.
Chris Dwyer