VS 2008/2010 different rendering? - asp.net

I had to change some code that was created by another person in VS2008, I converted it to the VS2010 version and was working just fine until the moment I needed to change a master page file. The moment I opened it, it gave me a lot of "does not exist in the current context" errors from the code behind showing that the code behind file could not find some of the controls declared in the master page file.
So, the code that gets errors is like this:
<li class='<asp:Literal ID="litLIClass_Test1" runat="server"/>'>stuff</li>
As you can see, the <li> CSS class is being generated inside that ASP literal, but it seems that the ASP literal doesn't get initialized.
However, it seemed to be working before, and I am trying to understand why it started giving me errors when I opened the page code for the first time in VS2010. Is there a particular setting that enables this kind of nesting? Could there be different settings in VS2008/2010?

In my experience, this is usually a Namespace not matching issue.
A few things to try:
I list this as #1 because it's the quickest, Make sure your local
web server is also turned off, Restart Visual Studio, Recompile (it
works sometimes in my experience). Make sure that the namespace in
your code behind file matches the namespace in your page (if it's
WebForms). I assume this also includes the master page but I don't
know, I do know that you can get this error when the ASPX and the
code behind namespaces are off.
If it's a code behind scenario, make sure the form is inherited properly.
Make sure you're not missing a reference you need. This is a common
cause of the error, especially when upgrading. Your code files
maybe identical but your web.config or what is referenced by default
might have changed.
I've read that this can be caused by two forms pointing to the same
code file, but I've never actually experienced that (nor do I do
that).
References:
http://msdn.microsoft.com/en-us/library/t8zbaa6f.aspx
http://geekswithblogs.net/mikehuguet/archive/2011/01/03/143332.aspx
(I had more reference links to post but I can't because I don't have the reputation yet). ;)

Related

Compilation errors after migrating to Visual Studio 2013: X is not a member of Y_aspx

We're trying to upgrade a large VS2010 solution to VS2013, and among the various issues, this one seems the most confusing.
The solution worked at first, but after a couple of builds, we started getting
error BC30456: 'InitializeCulture' is not a member of 'ASP.main_[whateverpage]_aspx'
This is an issue that used to happen occasionally with VS10, but it would always be fixed with a clean & rebuild. Now it simply refuses to go away.
Additionally, if you create a function called InitializeCulture in the aspx.vb file, it will simply show an error about some other property of either the page we're trying to open or the base Page class. It's as if the generated ASP.main_whateverpage_aspx class doesn't see the members of the classes it inherits from. What could be causing this?
Edit: We've discovered that this only happens on pages which inherit our myPage class (a simple extension of Page with a couple of common methods). This class is inside its own project, which was untouched by VS when it was migrating. Moving the class to the Main project makes the error go away, but I'd rather not do that unless I at least know why.

Making changes to a precompiled website

As seems my life at present, I have inherited yet another project that needs changing.
However this code has been precompiled (and guess what...)
I have what puports to be some of the source code, and a set of assemblies form the temp folder. However the project is moaning about missing some user controls and a master page in a sub directory.
I cannot see these anywhere in the assembiles I have, and they are not in the code I took from the website. So, where do I find the UI part of precompiled masterpages and user controls ?
You can use an IL decompiler like ilspy or reflector on the compiled website DLL and retrieve the original source code from it.
This is likely to take quite a bit of time and effort, but you should be able to reconstruct most of the missing source this way (though you will probably not have the correct variable names or exactly the same code and definitely no comments).

Support legacy code without access to compiled code behind

I have been asked to support a legacy app and I can't get access to the code behind files. I need to add a new feature that gets a list of items from the database on page_load, what way would adding an "in-page" page_load affect the compiled page_load?
What would be the best approach to take with this?
Since you mentioned that the legacy app has a Page_Load I assume it's .NET. This means that you should be able to decompile it using Reflector from Redgate to get the original source.
The source will likely be much less "pretty" than it was originally, but you should be able to get editable, compilable source out of it.
As for the question of an in-page page load and a compiled page load - You can try it... But I doubt it will work. You're really better off trying to get the source if you can.

New asp "showat" attribute required inconsistently in VS2010. Why?

When I generate code using T4 templates in Visual Studio 2010, I get the following error for each of my asp controls when I try to compile:
Control "ddState" is missing required attribute "showat".
I have never gotten this error in previous versions of .NET. Further, I don't get this error when I manually construct my pages either by dragging/dropping, nor do I get it when I type out the control text myself. When I generate code, I have to manually add showat="client" to my tag for the compiler to be happy. It was my understanding that I never had to explicitly specify this tag. The following:
<asp:dropdownlist id="ddState" runat="server" showat="client" />
solves the problem. Why do I have to add this to generated code but not other times?
(It's a VS-2010 webforms project, using VB, in case that makes a difference.)
Apparently .NET 5 or another one of those super service packs is going to allow something called targeted rendering. It was originally intended for use just in the context of webforms, but I've heard recently there will be some fancy way to use it in MVC (using some helper classes) and in services using WCF. It will work well with Dynamic Data but is very loosely coupled with it; you can use one or the other completely independently. If you configure your dynamic data with certain tags you can have it constructed on the client, etc.
For now, just put showat="client" in all your tags, and all is good. That's supposed to be the implicit default, but I've heard of cases where the IDE seems to require it. In the future, showat="client" will be the safest setting anyway, giving the expected behavior in 99.9% of cases.
This is required in VB, but not C#, which is why it seems to not be necessary sometimes. To be more specific, the C# compiler puts the equivalent of showat=client into the IL automatically, unless you specify a showat target other than client.
"showat='client'" should currently have little effect on your coding. It's main purpose is for future WCF output targeting, which they will want to be backward compatible. For now, the only possible value is "client", but in the future there will be other possible values that will allow pre-rendering of cached values, and apparently "pushing" output to services. The example I saw at the last code camp was where you could push to a service at (probably) the same site as well as to the client machine, for logging/debugging purposes. You'd have something like (to use your example):
<asp:dropdownlist id="ddlCP" runat="server" showat="client, logService" />
. . . and then the rendering would go to your log file. Or, to your session provider (if you've got multiple web servers and are implementing a shared session provider), etc. I think logService above would have to be defined in the web.config or something.
Check to see if VB does anything in the web form designer page when you use the IDE to add the control. I'm not sure how VB inserts the implicit tag. But that would be something the T4 template would miss, just a thought...
Agreed that my VS2010 solves this issue for you. Then you can remove the tags completely. I would suggest getting the upgrade. It's well work the $599 upgrade cost. Otherwise, look to add the showat="client" in all the tags. I think that Rising Star got that one right, although I haven't tested it yet.

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' (translated 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.

Resources