Install AJAX without web.config? - asp.net

I have a weird scenario, I need to use the AJAX ScriptManager and UpdatePanel on two specific ASP.NET 2.0 pages. The pages are in their own second-level directory (we don't want to make that directory a Virtual Directory). The root web.config is not AJAX enabled, and we don't want to change it.
Is is possible to use AJAX here, and how?
I was hoping it might be as easy as :
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

Is it an option for you to add a "local" web.config file in the sub directory in question? If you do so, all tags that are not present in the "local" file will be read from the "root" file.

You need to add a reference to System.Web.Extensions.dll to the application; without that, I'm pretty sure it's completely impossible.
However, if you just add a reference to that assembly to the root Web.config (without changing anything else), you should be able to register the tag prefix in your ASPX files, like this:
<%# Register tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" %>
I haven't tried it, though.
Please note that if the server isn't running .Net 3.5, you'll need to copy
System.Web.Extensions.dll to the application's Bin folder.

I believe you can create a web.config in your target folder that overrides the settings of the global web.config in the application root.
See
http://www.codeproject.com/KB/aspnet/multipleWebConfig.aspx
Mind you, I haven't tried this with tag registration, so YMMV.

Related

Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The system cannot find the file specified

I am working on sharepoint 2010. I have created a simple visual web part which contain one text box and I have added calendarextender to it. I have added ajaxcontroltoolkit.dll as reference. But when I deploy to sharepoint site then it gives me following error.
"Parser Error" Message:
Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The system cannot find the file specified.
Source Error:
Line 3: <%# Register Assembly="AjaxControlToolkit"> Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
Source File:
/_CONTROLTEMPLATES/VWP_Ajax/VisualWebPart1/VisualWebPart1UserControl.ascx Line: 9
Any ideas where Im going wrong?
Is the AjaxControlToolkit.dll in the bin directory after you deploy the site?
The assembly (AjaxControlToolkit.dll) needs to be deployed to the Global Assembly Cache (GAC) or put in the \BIN folder of the SharePoint site's folder.
This definitely worked for me with SharePoint 2010 ...
Error Code:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxControlToolkit"%>
Working Code:
<%# Register Assembly="AjaxControlToolkit, Version=3.5.60501.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" Namespace="AjaxControlToolkit" TagPrefix="ajaxControlToolkit"%>
Another possible solution is to explicitly set the full assembly name in your register command. I found that I had to update my code to include this to get it to work properly:
<%# Register Assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
For third-party controls like this, it's worth being as specific as possible to avoid any errors if versions change.
Even you tried above and it wont work, Just add another Page/MasterPage and add ToolKitScriptManager on it.It will create Bin Folder at required path. If still there is Error check the Register Assembly line on newly added page/MasterPage and copy that Register Assembly line to other pages wherever your error is.

Custom Control in ASP.NET C#

I created a simple custom control that only inherits from the Literal control, and doesn't have any extensions yet, code is empty.
Namespace: CustomControls
Class name: Literal : System.Web.UI.WebControls.Literal
Next thing I do is registering this control in the aspx page as following:
<%# Register TagPrefix="web" Namespace="CustomControls" %>
(I read in few tutorials that this is one of the ways to register it, besides web.config etc.)
After all, no intellisence for me, and worse- I get a parse error 'unknown server tag: web' when I try to run the page with the control in it.
I used 'create new project' and not new website, in case this info is needed.
What could be my problem?
Thanks in advance.
Here is how I did it, step by step starting from nothing. This first method uses a second project/assembly. For the App_code version scroll down.
Web Application Project Method
Create a new ASP.Net Web Application. Take note of the name, mine is called WebApplication2. If you already have an existing web application, which is likely, double click the properties section of your project and check the "Assembly Name" property, make note of it.
Create a new Class in the web applcation named Literal.cs
Put in code similar to the following for the class defenition:
namespace CustomControls
{
public class Literal : System.Web.UI.WebControls.Literal
{
}
}
Add the following register tag to the top of your aspx page
<%# Register assembly="WebApplication2" namespace="CustomControls" tagprefix="web" %>
If your assembly name was different then change it here. I noticed that when I did this in VB.Net the namespace was WebApplication1.CustomControls instead of just CustomControls like it was in C#, kind of odd.
Add the new control to your page:
<web:Literal ID="Literal1" runat="server" Text="test" />
Seperate Project Method
Create a new Empty Website (ASP.Net).
Add a new ASP.Net Server Control library named CustomControls to the solution.
Add a new Class to the new project called Literal (I'm using C# so my file is named Literal.cs). Below is my super basic code, that I believe should match the code described in the question.
namespace CustomControls
{
public class Literal : System.Web.UI.WebControls.Literal
{
}
}
Add a reference to the CustomControls project to your website.
Add the assembly registration to the top of your aspx page:
<%# Register assembly="CustomControls" namespace="CustomControls" tagprefix="web" %>
Add a new instance of the control to your page:
<web:Literal ID="Literal1" runat="server" Text="test" />
In App_Code Method
Create a new Empty Website (ASP.Net).
Add a new Class to the App_Code folder Literal2 (I'm using C# so my file is named Literal2.cs). Below is my super basic code, that I believe should match the code described in the question. I called it 2 so that you can use this in conjunction with the method described above without getting compile errors
namespace CustomControls
{
public class Literal2 : System.Web.UI.WebControls.Literal
{
}
}
Register the assembly/namespace for app_code in your aspx page by adding the following line to the top
<%# Register Namespace="CustomControls" Assembly="__code" tagprefix="web" %>
Add an instance of the new control to your page:
<web:Literal2 ID="literal2" runat="server" Text="test2" />
I tested this using visual studio and it all worked fine for me.
You can also register your control in web.config if you would like to use it on other pages
<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"/>
<add tagPrefix="web" namespace="MyProject.CustomControls" assembly="MyProject" />
</controls>
</pages>
For web site this will work
<add tagPrefix ="web" namespace="ASP.App_Code.CustomControls" />
The problem lies in your <%# Register TagPrefix="web" Namespace="CustomControls" %> tag: it misses the assembly name!
It must become <%# Register TagPrefix="web" Namespace="CustomControls" Assembly="YourAssemblyName" %>. If you have difficulties finding the assembly name for your class here are a few hints:
If you created the class inside the web application's Visual Studio project, or in a separate DLL (shared library) project, then right-click the project and go to Properties to get the assembly name
If you created the .cs file in App_Code directory, ASP.App_Code should work
Otherwise please give us some information about project layout!
The easiest thing to do is to drag-and-drop the Literal.ascx on to the page (if the page is in the same solution) .If the page is another solution, you could add the control to VS toolbox and drag-and-drop the control on the page.
You forgot the src attribute.
<%# Register TagPrefix="web" Namespace="CustomControls" Src="PathToYourCustomControl" %>

How do I add a reference to a server control in my current website to the web.config

I have extended a server control (not a user control) and put the code in my app_code folder.
I would like to add a tag prefix to the web config, but
<add tagPrefix="cc1" namespace="mynamespace" />
and
<add tagPrefix="cc1" namespace="mynamespace" assembly="currentwebsitename" />
don't work.
I get this error:
Error 147 Unknown server tag 'cc1:Control'
To register server controls that are in the App_Code folder, you only need the tag prefix and namespace. So in web.config it would look like this...
<add tagPrefix="cc1" namespace="mynamespace"/>
And in a page it would look like this...
<%# Register TagPrefix="cc1" Namespace="mynamespace" %>
One gotcha to watch out for is that by default web site projects don't include any namespace at all when you add a new item to the App_Code folder, so you'll need to explicitly make sure your controls have a namespace.
You either need to put the control into a DLL named "currentwebsitename.dll" (if you want it to work the second way) or you need to specify the source via the src attribute (if you want to do it the first way):
<add tagPrefix="cc1" namespace="mynamespace" src="app_code/control_name_here"/>
Try reading over these two articles as well:
http://msdn.microsoft.com/en-us/library/sbz9etab.aspx and
http://msdn.microsoft.com/en-us/library/yhzc935f.aspx

VB webform in IronPython asp.net website

I tried to bring a previously done webform made in vb.net to an IronPython asp.net website with no luck. After seeing it didnt work, I tried to write the simplest codebehind vb.net webform to see if there was a problem with vb.net in an IronPython website and I got the following usual error
"be sure that the defined class in this file matchs with the one in the attribute inherits and that it extends the right base page (page or control)" (sorry if the translation isnt the most accurate I get that message in spanish)
but if I create a vb.net webform in the same website, with the sourcecode in the same file (with the vb.net code between script runat="server" tags in the same page) I get no problem.
Do I have to configure something for both kind of sourcecode languages to run in such way in the same IronPython website, like configuring something in the webconfig file or is there some compatibility issue for doing that which can't be resolved?
The code between <script /> tags is compiled dynamically when the page is first run. This enables you to mix languages. However, the classes in your code-behind files are statically compiled into an assembly by VS.NET ... and a VS.NET project can only support one language at a time.
One solution is to put your VB.NET code-behinds in a separate assembly. For example:
Add a new VB Class Library project to your existing solution
Add a reference to System.Web
Create your VB.NET code-behinds. They should be normal classes inheriting from System.Web.UI.Page.
In your ASP.NET website project, add a reference to the new project
Edit the # Page directives in your *.aspx files to inherit the classes in the new project
e.g. <%# Page Inherits="YourNewVBClassLibraryProject.MyVBCodeBehinds" ... /> where the Inherits attribute contains the relevant namespace-qualified class name
Thanks for the reply Serilla. Your information was interesting but I simply solved it by creating the app_folder and adding the vb files there. Do you think I could have some future problem for doing so?
The problem with the vb files was when these lines in the web.config were enabled for Ironpython to work
<pages compilationMode="Auto" pageParserFilterType="Microsoft.Web.Scripting.UI.NoCompileCodePageParserFilter" pageBaseType="Microsoft.Web.Scripting.UI.ScriptPage" userControlBaseType="Microsoft.Web.Scripting.UI.ScriptUserControl">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
when I removed them, vb code behind files worked but ironpython didnt. When the lines were there, Ironpython code behind files worked but vb ones didnt

Visual Studio 2008 user controls registered in the web.config not registering with intellisense

I have a C# Web application built in Visual Studio 2008 where we rely heavily on user controls for 'pre-built' blocks of ASP.NET.
Instead of registering a big stack of user controls on each page, we register all the controls in a local (to a specific folder) web.config file. The advantage is that we can use the controls and the pages look 'cleaner' in source view. However, neither the VS2008 Design view nor Intellisense recognize the fact the controls are registered in web.config. However, the application itself works as expected.
Normally at the top of each page we'd have a tag like this:
<%# Register src="~/CommonControls/Foo.ascx" tagname="Foo" tagprefix="Bar" %>
And we register the controls in a local web.config like so:
<?xml version="1.0"?>
<configuration>
<system.web>
<pages>
<controls>
<add src="~/CommonControls/Foo.ascx" tagName="Foo" tagPrefix="Bar"/>
</controls>
</pages>
</system.web>
</configuration>
Does anyone know of a fix for getting Intellisense to recognize these custom controls? Or, is there a 'better' way of doing this?
Whilst this doesn't work in a local Web.Config file you can use the Location tag in your root web.config file to achieve the same result.
For example:
<?xml version="1.0"?>
<configuration>
<location path="MyPath">
<system.web>
<pages>
<controls>
<add src="~/CommonControls/Foo.ascx" tagName="Foo" tagPrefix="Bar"/>
</controls>
</pages>
</system.web>
</location>
</configuration>
It probably has to do with the fact that it isn't registered in the main web.config file. Test it out by putting one or two references in the main web.config file.
I tried your sample code and Intellisense works in both the code view of the aspx page and the code behind page. You might check the class names of your user controls, visual studio includes the folder name in the class name by default. So your control may be named CommonControls_Foo instead of Foo as you would expect.
Either way the web.config file has nothing to do with the Intellisense of the code behind. Check the name and namespace of the class.
Could it because you are registering the control twice and intellisense is unable to resolve the reference?
I would exepect that the control should be registered in either a config file or in the page directive

Resources