Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net controls not found in the code behind when implementing resources

Since we implemented globalization in our ASP.net website, we are getting some intellisense problems.

When the resource is added to an asp.net control, we receive errors. Even though the error is shown in visual studio, the application works!

For example, the following button

 <asp:Button runat="server" ID="BtnSave" Text="<%$ Resources:ResourceName, Save %>" OnClick="BtnSave_Click" />

Is not recognized in the code behind:

intellisense problem

The error is only shown when the code behind is open. But in the browser it works!

The same button without the resource reference works well:

 <asp:Button runat="server" ID="BtnSave" Text="Save" OnClick="BtnSave_Click" />

This is a custom SQL resource provider factory, added to the web.config:

 <globalization resourceProviderFactoryType="MyNamespace.SqlResourceProviderFactory" />

I tried deleting the cache and restarting the computer already.

Do you have any tips on how to find the issue?

Thanks in advance.

like image 382
Schiavini Avatar asked Jul 04 '12 15:07

Schiavini


People also ask

How do you implement code-behind?

If you precompile your code-behind classes into an assembly, you can use the Inherits attribute to specify the class from which to inherit. In this scenario, you do not have to include the actual code-behind class file when you deploy the application. Instead, you must deploy the assembly and the . aspx page.

How is a ASP.NET presentation page associated with its code-behind?

The code-behind feature of ASP.NET enables you to divide an ASP.NET page into two files - one consisting of the presentation data, and the second, which is also called the code-behind file, consisting of all the business logic.

What is ASPX and ASPX CS?

aspx. cs code is run server side, while the . aspx file is compiled on the server and is then served to the web client requesting it. Additionally, for MVC, I would suggest using a different view model, specifically Razor, which uses .


2 Answers

I had this problem when I created a new VS2010 solution and dragged in an existing website. To solve it right click on the project and 'Convert to Web Application' which will create designer files and fix the intellisense problems.

like image 191
AshRolls Avatar answered Oct 10 '22 22:10

AshRolls


Had this a few times myself, but unreleated to globalization.

I always solved it by restarting VS (which it looks like you've tried) or checking the class names in the front end code and back and code are the same.

It sounds like a stupid thing, but if you copy a page, then the class name doesn't update so the bindings go a little skewiffy (that's a technical term).

May not help, but it's something to check.

like image 42
Dark Hippo Avatar answered Oct 10 '22 20:10

Dark Hippo