Hello all,
I'm trying to use a CascadingDropDown Control in my application, but it isn't working, and I'm sure I'm following the instructions. Can anybody see what's wrong please? The page loads ok but the DropDownList Control that should be dynamically populated isn't. Instead, it displays an option that reads "method error 12031". I'm using Visual Studio .NET version 8 to develop, debug and run my application. Here's what I'm doing:
Firstly, the aspx page:
<asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:DropDownList runat="server" id="department" /> <asp:DropDownList runat="server" id="role" /> <AjaxToolkit:CascadingDropDown runat="server" id="CascadingDropDown1" TargetControlID="role" Category="role" PromptText="select a role" LoadingText="Loading roles..." ServicePath="~/WebModules/RoleAdmin/Services/RolesService.asmx" ServiceMethod="GetRolesInDepartment" />
Secondly, the Web Service referenced by the CascadingDropDown's ServicePath Property, which is in the "~WebModules/RoleAdmin/Services/RolesService/" directory:
<%@dotnet.itags.org. WebService Language="VB" CodeBehind="~/App_Code/RolesService.vb" Class="RolesService" %>
Thirdly, the CodeBehind for the WebService, which is in the "~/App_Code" directory. As you can see, for testing purposes it's as simple as it can be. It doesn't even look at a database!
Imports System.WebImports System.DataImports System.CollectionsImports System.Web.ServicesImports System.Web.Services.ProtocolsImports AjaxControlToolkitImports Harcourt.TMSUser.WebModules.RoleAdmin.Business<WebService(Namespace:="Harcourt.TMSUser.WebModules.RoleAdmin.Services")> _<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _Public Class RolesServiceInherits WebService <WebMethod()> _Public Function GetRolesForDepartment( _ByVal knownCategoryValuesAs String, _ByVal categoryAs String) _As CascadingDropDownNameValue()Dim returnCascadingDropDownNameValues(3)As CascadingDropDownNameValue returnCascadingDropDownNameValues(0) =New CascadingDropDownNameValue("A role","1") returnCascadingDropDownNameValues(1) =New CascadingDropDownNameValue("Another role","2") returnCascadingDropDownNameValues(2) =New CascadingDropDownNameValue("The last role","3")Return returnCascadingDropDownNameValuesEnd FunctionEnd Class
I have remembered to put the AjaxControlToolkit.dll assembly in my "~/Bin" directory, and I have registered it in my web.config file.
So what could possibly be causing this error? I couldn't have made the method much simpler, and it is returning valid XML if I run the web service directly. Can anybody explain why I am recieving this 12031 method error, please?
Many thanks in anticipation of your advice.
Ben
On further research, I have come accross posts that suggest I MIGHT have to decorate the web service class with a <Microsoft.Web.Script.Services.ScriptService()> _ attribute as well as the <WebService()> _ attribute.
However, Visual Studio .NET doesn't like it when I do this. It says "type Microsoft.Web.Script.Services.ScriptService is not defined".
I tried importing the namespace containing that class but apparently it can't find that either:
Where is the Microsoft.Web namespace?
My application doesn't know. Do I need to write something in web.config to show it where to go?
Or am I completely on the wrong track anyway?
Any advice would be very much appreciated! Thank you.
Which version of AJAX are you running? Release 1.0 RTM should need
"System.Web.Script.Services.ScriptService()" vs "Microsoft.Web.Script.Services.ScriptService()"
Thanks for your reply, LSU.Net,
I'm using the version I downloaded the day before yesterday! So I guess the most recent version.
Are you saying I need a particular one of those two attributes, or both, or will either do?
There is no longer a Microsoft.Web namespace. You will need only the System namespace.
Thank you! At least now I can get it to compile and launch ok, now that I have the correct namespace and have tweaked my web.config file.
However, I'm still having trouble. This time it's on the client side. I have a javascript error "Error: 'name' is null or not an object". This error appears as soon as the page loads. The second drop down in my page is disabled, by the Ajax CascadingDropDown, and the SelectText is displayed. However, because of the Javascript error, the Control does not function in the browser at all.
Any ideas what causes this problem, please?
I reimplemented your code and still had problems... Error 500s and such. I did a PageMethod and it worked. Note: I removed your custom namespaces.
In the page: Example Default5.aspx:
<asp:DropDownList runat="server" id="role" /> <AjaxToolkit:CascadingDropDown runat="server" id="CascadingDropDown1" TargetControlID="role" Category="role" PromptText="select a role" LoadingText="Loading roles..." ServicePath="Default5.aspx" ServiceMethod="GetRolesForDepartmentPageMethod" />
In Default5.aspx codebehind:
[WebMethod] [System.Web.Script.Services.ScriptMethod]public static CascadingDropDownNameValue[] GetRolesForDepartmentPageMethod(string knownCategoryValues,string category) {return new RolesService().GetRolesForDepartment(knownCategoryValues, category); }
RolesService.cs:
[WebMethod] [System.Web.Script.Services.ScriptMethod]public AjaxControlToolkit.CascadingDropDownNameValue[] GetRolesForDepartment(string knownCategoryValues,string category) { CascadingDropDownNameValue[] returnCascadingDropDownNameValues =new CascadingDropDownNameValue[3];//Dim returnCascadingDropDownNameValues(3) As CascadingDropDownNameValue returnCascadingDropDownNameValues[0] =new AjaxControlToolkit.CascadingDropDownNameValue("A role","1"); returnCascadingDropDownNameValues[1] =new AjaxControlToolkit.CascadingDropDownNameValue("Another role","2"); returnCascadingDropDownNameValues[2] =new AjaxControlToolkit.CascadingDropDownNameValue("The last role","3");return returnCascadingDropDownNameValues; }
Thank you very much, I'll give it a try after lunch, but do you know why I can't use a separate web service? I thought that was supposed to be within the capabilities of the CascadingDropDown Control.
You should be able to, but I had problems. I'm unsure why.
Have a look at the ToolkitTests\CascadingDropDown.aspx automated test case that comes with the Toolkit for an example of using a Web Service (vs. a Page Method).
This cascadingdropdown control is a complete waste of time. I've tried everything, web service, page methods, static, in a user control, in a aspx page... all I get are 12031, 12030, and 500 errors.
You probably didn't make your function shared.
also Im not sure if its required but you should have your script managerEnablePartialRendering="true"
<WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
PublicSharedFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue()Dim kvAs StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim iProductIDAsInteger = 0ForEach deAs DictionaryEntryIn kviProductID = de.Value.ToString()
Next
Dim dsAs Data.DataSet = fill your dataset
Dim valuesAsNew List(Of CascadingDropDownNameValue)ForEach drAs Data.DataRowIn ds.Tables(0).Rows
Dim vAsNew CascadingDropDownNameValuev.name = dr("Version")
v.value = dr("VersionID")values.Add(v)
Next
Return values.ToArray
EndFunction
Eventually I made it work with DotNetNuke 4.5.3.
The way to do it is pretty hardcore!
0. Obtain the sources of the whole AjaxControlToolkit package.1. Copy two script files "CascadingDropDownBehavior.js" and "BaseScripts.js" from AjaxControlToolkit to the "~/DesktopModules/" dir of your site.
2. Rebuild the whole AjaxControlToolkit with the original files "CascadingDropDownBehavior.js" and "BaseScripts.js" madeEMPTY!
3. Add some lines to your .ascx module file as it is written here: http://www.adefwebserver.com/DotNetNukeHELP/Misc/Dotnetnuke_AJAX_webservices.htm
In our case we have 2 javascript files, so the code of Page_Load() will be like this:
...
if (DotNetNuke.Framework.AJAX.IsInstalled())
{
DotNetNuke.Framework.AJAX.RegisterScriptManager();
// Create a reference to the Script Manager
ScriptManager objScriptManager = ScriptManager.GetCurrent(this.Page);
// Add a reference to the web service
ServiceReference objServiceReference = new ServiceReference();
objServiceReference.Path = @."~/DesktopModules/YourModule/YourWebService.asmx";
objScriptManager.Services.Add(objServiceReference);
ScriptReference objScriptReference1 = new ScriptReference();
objScriptReference1.Path = @."~/DesktopModules/YourModule/BaseScripts.js";
objScriptManager.Scripts.Add(objScriptReference1);
ScriptReference objScriptReference2 = new ScriptReference();
objScriptReference2.Path = @."~/DesktopModules/YourModule/CascadingDropDownBehavior.js";
objScriptManager.Scripts.Add(objScriptReference2);
}
...
4. Build your website. Voila!
Sorry, if something is not clear enough. I've spent the whole night trying make it work.. )
I've managed to get this working on my PC. For some reason using upper case characters in XML element names causes a problem (the example in the toolkit uses: make, model and color, not Make, Model and Color). Also I think the name of the the XML file has to be the same as the service as well - eg. CarsService.cs relates to CarsService.xml. I might be completely wrong but that's the only way I could get it to work for me... I recommend copying and tweaking the code from the Tool kit sample one bit at a time.
No comments:
Post a Comment