Hi there,
I am just trying to learn AJAX at the moment and have run into a problem. I have copied over the example for cascading dropdowns and this is where I have the above error.
The error occurs in the web.config file on this line<
add assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>Can anyone advise what I need to change?
![]() |
0 |
![]() |
The sample is for old ajax version.
you need to copy latest ASP.NET AJAX web.config to your projects web.config
below is my cascading code for new version for you
ASPX
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="CascadingDropDownDemo._Default" EnableEventValidation="false" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="sm" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="upMain" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddl1" runat="server" Width="275px">
</asp:DropDownList><br />
<asp:DropDownList ID="ddl2" runat="server" Width="275px">
</asp:DropDownList><br />
<asp:DropDownList ID="ddl3" runat="server" Width="275px">
</asp:DropDownList><br />
<cc1:CascadingDropDown ID="ccd1" runat="server" TargetControlID="ddl1" Category="Make"
PromptText="Please select a make" ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="ccd2" runat="server" TargetControlID="ddl2" Category="Model"
PromptText="Please select a model" ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents"
ParentControlID="ddl1">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="ccd3" runat="server" TargetControlID="ddl3" Category="Color"
PromptText="Please select a color" ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents"
ParentControlID="ddl2">
</cc1:CascadingDropDown>
<asp:Button ID="btnClick" runat="server" Text="I want this car." Width="282px" OnClick="btnClick_Click" /><br />
<br />
<asp:Label ID="lblInformation" runat="server" Text="[ No sellection made yet. ]"
Width="279px"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel> </div>
</form>
</body>
</html>Code Behind
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.Web.Services.Protocols;namespace CascadingDropDownDemo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
protected void btnClick_Click(object sender, EventArgs e)
{
// Get selected values
string make = ddl1.SelectedItem.Text;
string model = ddl2.SelectedItem.Text;
string color = ddl3.SelectedItem.Text;// Output result string based on which values are specified
if (string.IsNullOrEmpty(make))
{
lblInformation.Text = "Please select a make.";
}
else if (string.IsNullOrEmpty(model))
{
lblInformation.Text = "Please select a model.";
}
else if (string.IsNullOrEmpty(color))
{
lblInformation.Text = "Please select a color.";
}
else
{
lblInformation.Text = string.Format("You have chosen a {0} {1} {2}. Nice car!", color, make, model);
}
}[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public static AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContentsPageMethod(string knownCategoryValues, string Category)
{
CarsService cs = new CarsService();
return cs.GetDropDownContents(knownCategoryValues, Category);
}protected void ddl3_SelectedIndexChanged(object sender, EventArgs e)
{
string make = ddl1.SelectedItem.Text;
string model = ddl2.SelectedItem.Text;
string color = ddl3.SelectedItem.Text;// Output result string based on which values are specified
if (string.IsNullOrEmpty(make))
{
lblInformation.Text = "Please select a make.";
}
else if (string.IsNullOrEmpty(model))
{
lblInformation.Text = "Please select a model.";
}
else if (string.IsNullOrEmpty(color))
{
lblInformation.Text = "Please select a color.";
}
else
{
lblInformation.Text = string.Format("You have chosen a {0} {1} {2}. Nice car!", color, make, model);
}
}
}
}web services code
using System;
using System.Web;
using System.Collections;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;using AjaxControlToolkit.Design;
namespace CascadingDropDownDemo
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class CarsService : System.Web.Services.WebService
{
// Member variables
private static XmlDocument _document;
private static object _lock = new object();
// we make these public statics just so we can call them from externally for the
// page method call
//
public static XmlDocument Document
{
get
{
lock (_lock)
{
if (_document == null)
{
// Read XML data from disk
_document = new XmlDocument();
_document.Load(HttpContext.Current.Server.MapPath("~/CarsService.xml"));
}
}
return _document;
}
}public static string[] Hierarchy
{
get
{return new string[] { "make", "model" };
}
}/// <summary>
/// Constructor to initialize members
/// </summary>
public CarsService()
{
}
/// <summary>
/// Helper web service method
/// </summary>
/// <param name="knownCategoryValues">private storage format string</param>
/// <param name="category">category of DropDownList to populate</param>
/// <returns>list of content items</returns>
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
{
// Get a dictionary of known category/value pairs
StringDictionary knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);// Perform a simple query against the data document
return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category);
}
}}
Good luck
James Wu (MIB426)
.NET is only way to go
MCP, MCSE, MCDBA, MCSD, MCAD
![]() |
0 |
![]() |
Hi MIB426,
Thanks heaps for your code....I am pretty new to both .NET & AJAX so I need to be a pain and ask a couple more questions.
Where can I get the web.config file from?
This part of your code (web services code) where am I meant to add this to?
Thanks heaps for your help!
using System;
using System.Web;
using System.Collections;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;using AjaxControlToolkit.Design;
namespace CascadingDropDownDemo
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class CarsService : System.Web.Services.WebService
{
// Member variables
private static XmlDocument _document;
private static object _lock = new object();
// we make these public statics just so we can call them from externally for the
// page method call
//
public static XmlDocument Document
{
get
{
lock (_lock)
{
if (_document == null)
{
// Read XML data from disk
_document = new XmlDocument();
_document.Load(HttpContext.Current.Server.MapPath("~/CarsService.xml"));
}
}
return _document;
}
}public static string[] Hierarchy
{
get
{return new string[] { "make", "model" };
}
}/// <summary>
/// Constructor to initialize members
/// </summary>
public CarsService()
{
}
/// <summary>
/// Helper web service method
/// </summary>
/// <param name="knownCategoryValues">private storage format string</param>
/// <param name="category">category of DropDownList to populate</param>
/// <returns>list of content items</returns>
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
{
// Get a dictionary of known category/value pairs
StringDictionary knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);// Perform a simple query against the data document
return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category);
}
}}
![]() |
0 |
![]() |
Sorry its me again.
Ok I have created a new page called default2.aspx and added the above code. I created a new web service "WebService" and added the above code into WebService.cs.
When I try run the the form I get an error saying "Error 29 Could not create type 'WebService'. C:\Users\shane\Desktop\AJAXEnabledWebSite4\WebService.asmx 1"
What else do I need to change......Please help!!!!!!!
Thank you
![]() |
0 |
![]() |