How to add ajax control in the project - asp.net

I am using asp.net using C#.I want to add Ajax Control to my Web Pages.I am using visual studio 2005.That had ajax basic control not extended control and bin folder contain ajax controltoolkit.dll.But when I am adding control to my page,it shows the unknown elements.I add references and select that file(dll).Still the assembly details is not coming in my aspx page.And still saying unknown element.I have another project also.In that I done same ,and it works also.

You'll need to edit your web.config
<add assembly="AjaxControlToolkit, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
Goes between
<assemblies></assemblies>
tag.
<add tagPrefix="ajaxToolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
Goes between
<controls></controls>
tag.

Related

Problem using Ajax with Visual Studio 2010

I am hoping someone can help me. I am trying to add Ajax controls to my VS 2010 project for the first time. I have previously gotten it to work when I used VS2008. I keep getting this exception:
Error 56 The type 'System.Web.UI.ExtenderControl' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Here’s what I did. I downloaded the ajax 4 toolkit and added a reference to the project. I also added a reference to system.web extension to my project. When I do this these lines get added to my web.config
<assemblies>
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></assemblies></compilation>
I added these lines to my aspx file.
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
And
<cc1:CalendarExtender runat="server" Id="txtDateOfBirth_CalendarExtender" TargetControlID="txtDateOfBirth"></cc1:CalendarExtender>
Etc.
I also backed off and tried ajax 3.5, this didn’t help. I did notice that the ajax dll is 4.1 while the 'System.Web.Extensions is 4.0. I don’t know if this matters but I cannot find ajax 4.0 or 'System.Web.Extensions 4.1.
Thank once again in advance.
This is not a solution but a recommendation: stay away from the Ajax toolkit or you are asking for trouble; use jquery instead (seriously, I have been down this road).

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 to use chart control's assemblies in application without installing it?

I am using a web application in which there is a chart control. I had installed the Microsoft chart control exe and Visual studio add on.
The problem is that when I upload the application on the server, there is a problem with the two assemblies missing System.Web.DataVisualization.Design.dll and System.Web.DataVisualization.dll.
So, I want to uninstall the Microsoft chart control exe & Visual studio add on, and instead only use the DLL in the application by giving reference in it.
Now, how do I define chart control on an ASPX page? How do I register the assemblies on the ASPX page and how can I get the chart control from it?
I think you can just add the DLL's to your Bin directory of your website.
Installing the chart controls locally simply adds the DLL's to your computer somewhere (I think). And I believe that the Add-In is to give you support for design mode. It doesn't install anything specific to your projects.
However, you may need to register the controls either on the page or in the web.config. For example, here is the registration of the AjaxControlToolkit controls in the web.config:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<pages>
<controls>
<add tagPrefix="ajaxToolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>
</controls>
</pages>
</system.web>
</configuration>
I have solved the problem.
First, add the library System.Web.DataVisualization.dll as reference.
Then, add the following line in web.config, inside <httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
You may see DataVisualization.Charting.ChartHttpHandler in red, it will build and run successfully. This may be a ReSharper bug.

How to fix the HTML Intellisense in ASP.NET AJAX Controls or Pages

I'm using ASP.NET AJAX. I create a .aspx page that is based on a .master file. I add the , , control into the content page, and suddenly the markup intellisense no longer works for these controls, or for any controls nested within them.
Is this a bug? Can I fix this?
The fix for the intellisense issue will be in VS 2005 SP1.
In the meantime there are two workarounds that you can use to fix it immediately:
1) Keep the .master file open within the Visual Studio IDE when working on the .aspx content page. It turns out the intellisense engine only runs into issues if the .master file is closed. As long as it is open within the same IDE, it resolves the assemblies just fine and will give you full intellisense
2) Go into your web.config file and change the tag-prefix naming for the ASP.NET AJAX controls to something other than . For example, instead of:
<controls>
<add tagPrefix="asp" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Extensions" />
<add tagPrefix="asp" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Extensions" />
</controls>
change them to something like this:
<controls>
<add tagPrefix="ajax" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Extensions" />
<add tagPrefix="ajax" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Extensions" />
</controls>
You'd then want to update your tag prefixes in your .aspx page to use this new tag prefix.
Either of these approaches will solve the problem and deliver full intellisense. The issue should then be resolved completely with VS 2005 SP1.

Registering User Controls in web.config Shows Error, But Controls Work Anyway

This has been bugging me all morning and I can't even figure out where the error is.
In the current web site I am developing (it's not a web application, in case it makes a difference, there are user controls declared as follows:
<controls>
<add tagPrefix="uc1" tagName="TransitLinkAdmin" src="~\controls\TransitLinkAdmin.ascx"/>
<add tagPrefix="uc1" tagName="TransitLinkList" src="~\controls\TransitLinkList.ascx"/>
<add tagPrefix="uc1" tagName="WelcomeMessageAdmin" src="~\controls\WelcomeMessageAdmin.ascx"/>
<add tagPrefix="uc1" tagName="WelcomeMessageDisplay" src="~\controls\WelcomeMessageDisplay.ascx"/>
<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>
So far so good, right?
But when I try to add one of these controls to a page, I get an error telling me that the control cannot be found. So why when I run the page, I can use the control?
The designer is telling me that it cannot find the user control file and it is using the path from the web.config file, so it must be looking at it in some fashion.
If I register the control directly in the page, no problems there.
My assumption (and we now how that works) is that there is some compilation error for the site as a whole that is preventing the intellisense from working.
Thanks in advance, all.
Just a complete guess, but maybe it is because you are using backslashes instead of forward slashes? Try:
<add tagPrefix="uc1" tagName="TransitLinkAdmin" src="~/controls/TransitLinkAdmin.ascx"/>
<add tagPrefix="uc1" tagName="TransitLinkList" src="~/controls/TransitLinkList.ascx"/>
<add tagPrefix="uc1" tagName="WelcomeMessageAdmin" src="~/controls/WelcomeMessageAdmin.ascx"/>
<add tagPrefix="uc1" tagName="WelcomeMessageDisplay" src="~/controls/WelcomeMessageDisplay.ascx"/>
Are you using resharper?
I am not sure what version, but somewhere along the way this artifact had happened.
try updating to the last version.
btw they have an early access program where you can download builds (decent quality), and be updatd with the latest features and fixes.
link to early access program
Close visual studio
Move to the location:
In Windows 7:
C:\Users\Pavel\AppData\Roaming\Microsoft\VisualStudio\10.0\ReflectedSchemas
In Windows XP:
C:\Documents and Settings[your username]\Application Data\Microsoft\VisualStudio\10.0\ReflectedSchemas in windows XP
Delete all the files in that folder location. Note that it is completely safe to delete files in this location.
Then reopen visual studio.
This should solve your problem.

Resources