Defining tagPrefixes in Web.config help - asp.net

I am having a little bit of trouble getting my aspx pages to recognize my tagPrefixes.
I have the standard ASP ones defined...
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Then I have my custom controls defined below that but I do not think I am defining them properly because sometimes the page does not see any controls in the current context other times they work like a champ...
<add tagPrefix="mri" namespace="Mri.Controls" assembly="Mri.Controls"/>
<add tagPrefix="mri" namespace="Mri.Controls.Inputs" assembly="Mri.Controls"/>
<add tagPrefix="mri" namespace="Mri.Controls.Inputs.DropDowns" assembly="Mri.Controls"/>
<add tagPrefix="mri" namespace="Mri.Controls.Inputs.Search" assembly="Mri.Controls"/>
I have one namespace "Mri.Controls" and inside of that namespace I have several sub-folders, "Inputs" -> "DropDowns" etc...
What am I doing wrong? Currently the regular ASP controls are giving me an error: The name "blahBlah" does not exist in the current context.

The sub-folders may or maynot become part of the namespace. By default, Visual Studio does include them when creating new classes but that can be removed in the class. If you moved the controls to the sub-folders, then the folder's name is likely not part of the namespace.
Also, make sure you are referencing your controls assembly or project within Visual Studio.

Do you not also need the tagName attribute e.g.
<add tagPrefix="mri" tagName="Search" namespace="Mri.Controls.Inputs.Search" assembly="Mri.Controls"/>
<mri:Search ID="Search" runat="server"/>

Related

Element 'UpdatePanel' is not a known element

I have one master page in project. I added scripmanager in that page. In one aspx page I added only update panel control because script manager is in master page.I open both file of master page and save. Still I am getting an error Element 'UpdatePanel' is not a known element.
Found this here
Basically quit VS2010, delete the content of your 'Reflected Schema Cache', which should be in something like this:
C:\Users\[Your Username]\AppData\Roaming\Microsoft\VisualStudio\10.0\ReflectedSchemas
Restart VS and you should have fixed it.
I had similar issue and I figured that if we have UpdatePanel under "div" or "span" or even "asp:Content" the VS intellisense doesn't complain. Its strange though.
I was experiencing the same problem and also tried to drag and drop from the toolbox to no avail. I finally was able to solve it by adding the targetFramework="4.0" attribute to my compilation tag in my web.config file.
Put the following code in your web config. Just change assembly according to your Ajaxtoolkit
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
</controls>
</pages>
This is one way to resolve the 'Element 'UpdatePanel' is not a known element' error if you're using VS2008 or targetting earlier frameworks.
You need to explicitly include the following controls/namespaces in your web.config's pages section, contained within system.web.
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<%# Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
I was getting this error in VS 2015 due to reference to 3.5 in System.Web.Extensions page directive. Make sure it's 4.0
Had the same problem when I changed from an older .Net to a later .Net 4 framework. Also changed to XHTML5.
In XHTML5 the is not allowed which was used, which affected parsing, which caused the error/warning.
Once I replaced with then it stopped the warnings.
Having the same problem, here is how I solved it:
With your ScriptManager, add it before your UpdatePanel, but close it's tag instead of putting the UpdatePanel and ContentTemplate inside of it.
<asp:ScriptManager ID="nonflashymanager" runat="server"/>
<asp:UpdatePanel id="nonflashyform" runat="server">
<ContentTemplate>
</ContentTemplate>
</UpdatePanel>

Failure to compile Linq Method in App_Code

I've been scratching my head for what seems like ages. I'm sure its really simple to fix but I can't see it.
I have a class in App_Code that uses a bit of Linq.
var siteMap = SiteMapWrapper.BuildSiteMap(true);
var currentTopLevelParent = siteMap.Single(s => s.IsActive);
if (currentTopLevelParent != null)
I've developed this locally and all works fine. When I transfer to IIS hosting the same class fails to compile. I receive:
does not contain a definition for 'Single' and no extension method 'Single'
accepting a first argument of type 'SiteMapWrapper' could be found (are you
missing a using directive or an assembly reference?)
I confirmed that the virtual dir is running .NET 2.0 as it should. I also confirmed that the correct assemblies are being loaded in the web.config.
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
I've tried adding namespaces directives in web.config also but no luck. Can anyone think of anything else to try?
Many thanks.
I think you will find that the server does not have 3.5 installed.
Add using System.Linq; to the top of the .cs file.
Also, make sure that SiteMapWrapper implements IEnumerable<T>.
EDIT: I didn't notice that it works on the local machine.
Make sure that the server has the correct versions of all of the dependent assemblies.
LINQ actually requires .NET 3.0 (3.5 is better), not 2.0. Make sure the AppPool is configured appropriately.
Change the Build Action Property of your .cs file from Content to Compile.
See this article for more info.

Where are components (dll) references stored in ASP.NET?

I have dlls in bin directory. I can't see where they are referenced in either solution or web.config files. So where are the references stored ?
The answer depends on if your project is a Web Site or a Web Application. In a Web Site all the assemblies in the bin directory are automatically referenced. A Web Application has the project references that you are looking for.
When working on a previously developed ASP.NET "WebSite" project in VS2012, I figured out how to find them (and thus add/remove/update them).
Over in the Solution Explorer, right-click the name of the project (the project will have the wire-frame globe icon next to it)
Click "Property Pages" (NOT Properties Window). It will appear in its own separate (floating) window frame.
Now just left-click the item "References" at the top of the list to the left. That's it! You can now add, delete, and update any reference(s) associated with your WebSite project.
If web app project or MVC, right-click and select unload project. Then right click again and select edit . If you dig through the XML, you will find the collection of project references and other DLL references to MS or other assemblies.
If you actually have them referenced, they should be "stored" in the project files (*.csproj for C#, *.vbproj for Visual Basic).
In the case of an ASP.NET web site, the references are stored in the web.config file.
I've removed most of the assemly references, but one of my old web sites has things like this:
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>

VS2008 targeting ASP.net 2.0: Project-level imports warning

I have a web app built against asp.net 2.0, but keep getting the following warning:
Namespace or type specified in the project-level Imports 'System.Xml.Linq' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
I cannot find anywhere that actually Linq is actually referenced. I've even opened up the .vbproj in a text editor, and it's not hidden in there either.
Any ideas where this is set?
Open your web.config and remove the reference to Linq in there. You should need to delete these lines from under the "assemblies" section:
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
Have you checked in your web.config file?
You also get this error if you have an older version of .Net Framework.
Go To Project->Properties->Advanced Compile Options->Target framework(all configurations)
If it is set to .NET Framework 2.0, try changing it to 3.5.
That fixed it for me.

Import Namespace System.Query

I am trying to load Linq on my .Net 3.5 enabled web server by adding the following to my .aspx page:
<%# Import Namespace="System.Query" %>
However, this fails and tells me it cannot find the namespace.
The type or namespace name 'Query' does not exist in the namespace 'System'
I have also tried with no luck:
System.Data.Linq
System.Linq
System.Xml.Linq
I believe that .Net 3.5 is working because var hello = "Hello World" seems to work.
Can anyone help please?
PS: I just want to clarify that I don't use Visual Studio, I simply have a Text Editor and write my code directly into .aspx files.
I have version 2 selected in IIS and I
Well, surely that's your problem? Select 3.5.
Actually, here's the real info:
http://www.hanselman.com/blog/HowToSetAnIISApplicationOrAppPoolToUseASPNET35RatherThan20.aspx
What does the part of your web.config file look like?
Here's what it looks like for a brand new ASP.NET 3.5 project made with Visual Studio 2008:
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
I found the answer :) I needed to add the following to my web.config:
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
Then I could add the following to my code:
<%# Import Namespace="System.Linq" %>
#Will,
Thanks for your help. I have accepted one of your answers :)
Make sure your project is set to target 3.5, and not 2.0.
As others have said, your 'var' test is a test of C#3 (i.e. VS2008), not the 3.5 framework.
If you set the project framework target settings properly, you should not expect to need to manually add dll references at this point.
The var hello stuff is compiler magic and will work without Linq.
Try adding a reference to System.Core
Sorry, I wasn't clear. I meant add System.Core to the web project's references, not to the page.
The Import on the page are basically just using statements, allowing you to skip the namespace on the page.
The csproj file might be missing the System.Core reference.
Look for a line in the csproj file like this:
<Reference Include="System" />
And add a line below it like this:
<Reference Include="System.Core" />

Resources