Showing posts with label method. Show all posts
Showing posts with label method. Show all posts

Wednesday, March 28, 2012

Change to invokeViaServer method

Why was the old ModalPopupBehavior.invokeViaServer method changed to remove the section that deals with the partial page update? I was using that method, and now that I'm migrating to the new code base .. I'm just a little confused.

Also, has anyone explained publically why getDescriptors is now gone?

getDescriptors is gone because the ASP.NET AJAX Beta (referred to as "Core") no longer supports TypeDescriptor. That stuff was mostly there to support XML Script, so it was no longer needed.

For the invokeViaServer stuff, much of that code shouldn't be needed anymore. I didn't do the work on that component so I'm not completely sure (David did the work and he's out of the office this week) if it's critical or not. Try it as is and report back if it's not doing the right thing. The way that components get called after a partial update has changed, it may address this scenario.


Oh, so .. was XML Script scraped? So many breaking changes for developers .. ^_^ Yea, I was using the invokeViaServer method for a few controls of mine, and was curious about the change while I was trying to migrate from the last CTP to the Beta. With so many changes, it's hard to tell. You can't see the list of check-in notes *easily* on the Codeplex site, which is where some of the documentation is going.

Even if you could, it probably wouldn't help. The number of checkins associated with the migration was well into the hundreds I'm sure (basically 3-6 people working 12+ hours a day for 2.5 weeks...) so it would be hard to pick things out.

Your better bet is to check out the migration materials onhttp://ajax.asp.net and my blog entry(s) on the subject athttp://blogs.msdn.com/sburke.

Change Object name in generated WSDL

Good day,

I have a Web Method that uses a simple custom object, name Client, as a parameter, and also returns a Client.

However, in the generated WSDL, I want "element name="Client" " to be changed to "element name="THE_CLIENT", but without changing the class name.

Is there a way to specify that an object should have another name in the wsdl, Something like [WebMethod(Description="DESCRIPTION")], but for a class?

Thank you, have a nice day!

Hi,

I think this link provide all information you need:http://msdn2.microsoft.com/en-us/library/2baksw0z.aspx

By default, an XML element name is determined by the class or member name. In a simple class named Book, a field named ISBN will produce an XML element tag <ISBN>, as shown in the following example.

Visual Basic

Copy Code

PublicClass BookPublic ISBNAsStringEndClass' When an instance of the Book class is serialized, it might' produce this XML:' <ISBN>1234567890</ISBN>.

C#

Copy Code

publicclass Book{publicstring ISBN;}// When an instance of the Book class is serialized, it might// produce this XML:// <ISBN>1234567890</ISBN>.

This default behavior can be changed if you want to give the element a new name. The following code shows how an attribute enables this by setting theElementName property of aXmlElementAttribute.

Visual Basic

Copy Code

PublicClass TaxRates < XmlElement(ElementName ="TaxRate")> _Public ReturnTaxRateAsDecimalEndClass

C#

Copy Code

publicclass TaxRates{ [XmlElement(ElementName ="TaxRate")]public decimal ReturnTaxRate;}

For more information about attributes, seeExtending Metadata Using Attributes. For a list of attributes that control XML serialization, seeAttributes That Control XML Serialization.

Best Regards

Change in behavior of RegisterStartupScript

In Beta 1, it is requried to use the ScriptManager.RegisterStartupScript method, and this method requires that a control that is within the partial update is passed as the first parameter.

All my pages inherit the same BasePage, and I wan't to register a startup script every time a partial update occurs, regardless of where the update is done.

Please change this back so that the Page.ClientScript.RegisterStartupScript method can be used!

Einar

I need a page based RegisterStartupScript as well. I haven't seen anything from Microsoft mentioning that they would bring this back. Is there a way to run Java Script from a class file?

Thanks,

Jennifer


We can't properly support RegisterStartupScript itself since there's no way to know what people registered. However, we're considering an option to allow people to call a new method (or perhaps change an existing method) to register scripts that should always get included in the async post.

Thanks,

Eilon


Thats great news Eilon, crossing my fingers, would simplify things a great deal :-)

By the way, big thanks to the team for all the great sessions in Barcelona last week!

Einar


Eilon,

This would be great. If the RegisterStartupScript of the ScriptManager did not require a reference to a control in an update panel, life would be much easier. Thanks,

Mark

Monday, March 26, 2012

Cascasding Drop Down Page method custom variable

Hi

I have page method populating the first of my drop downs and the reason being is that i need a variable that will be specific to user.
Currently this is stored in the session...How can i use this variable in the Page Method that is static...I cant really use a static variable as they are shared between all users.

Thanks.

Steve

Hi Steve,

Unfortunately I don't know of a good way to do this anymore. When we first wrote CascadingDropDown page methods weren't required to be static so there was an easy solution. Could you create a work item on CodePlex for this? Perhaps we could modify the web service signature to include optional tag info.

Thanks,
Ted

AAAAAHHHHH!!!!!

Well i have found a solution that works for me and may well for others.....
I have a web method that has Sessions enabled that i can call to get the value from...of course this method cannot be on the page as Sessions arent static.

[

WebMethod(EnableSession =true)]
publicCascadingDropDownNameValue[] GetDivisionsBySessionIdAccount(string knownCategoryValues,string category)
{
SessionCollection oSC; if (Session["UserObj"] !=null) {
oSC = (SessionCollection)Session["UserObj"];
// Calling another method to get my array - the same one i used from the page method.
CascadingDropDownNameValue[] retArray = GetDivisionsByIdAccount(oSC.idAccount);
return retArray;
}
else {
thrownewException("Your Session Has Expired");
}
}

I have created a work item number7579 for this.

---

I have just updated to the release toolkit and now my CCDD have stopped working! The top drop down loads fine from the method above but none of the others below. I have a debug error in jsSys.Debug is null or not an object.??

ARGH!


Here's more on the typical cause of Sys.Debug is null:http://forums.asp.net/thread/1546990.aspx

Cascasding drop down - Error 500

Hi
I am playing with the cascading drop down control...
i have written a method to get data from sql 05 database and return andarray of CascadingDropDownNameValue. (i watched one of the how towebcasts on it)....anyway, i can get it to work else where but forsome reason its not working with this one.
I know the method is returning the right data as i have another methodwhich returns all values in a string[] i then dump on the screen andall is ok.
My CCD declaration.

<atlasT:CascadingDropDownID="CascadingDropDown1"runat="server">

<atlasT:CascadingDropDownProperties

Category="CategoryName"

ParentControlID="ddlClass"

TargetControlID="ddlCourses"

PromptText="All"ServiceMethod="GetCoursesByIdClass"

ServicePath="webservices/FillDropDowns.asmx"/>

</atlasT:CascadingDropDown>

My method...

[WebMethod]

publicCascadingDropDownNameValue[] GetCoursesByIdClass(string knownCategoryValues,string category)

{

// Get connection string from web.config

string dsn = System.Configuration.ConfigurationManager.ConnectionStrings["connCleo"].ConnectionString;

string[] categoryValues = knownCategoryValues.Split(':',';');

int idClass =Convert.ToInt32(categoryValues[1]);

// SQL script

string sql =@dotnet.itags.org."SELECT c.idCourse, c.chrName FROM cleo.Course c

JOIN cleo.CourseAssign ca ONca.idCourse=c.idCourse

WHERE idClass=@dotnet.itags.org.idClass

ORDER BY c.chrName";

// Generic list for collection

List<CascadingDropDownNameValue> cascadeCollection =newList<CascadingDropDownNameValue>();

// Open connection and execute command...loop through reader and add items to list.

using(SqlConnection conn =newSqlConnection(dsn))

using (SqlCommand cmd =newSqlCommand(sql, conn))

{

cmd.Parameters.AddWithValue("@dotnet.itags.org.idClass", idClass);

conn.Open();

using (SqlDataReader reader = cmd.ExecuteReader())

{

while (reader.Read())

{

cascadeCollection.Add(newCascadingDropDownNameValue(reader.GetString(1), reader[0].ToString()));

}

}

}

// return collection as an array.

return cascadeCollection.ToArray();

}


I dont know of anyway i can debugthis to see if i am infact getting the correct values back(not surewhat values i need to pass to the method to mimic the call from thetoolkit.)?

Hopefully someone can see where i am going wrong.??

Thanks
Steve

OK, so i am pulling my hair out and have no idea where to look for help other than here.

I have put the same code in another project and it works fine.

The only difference that i can see is the version of the Atlas and Toolkit dll.

The date stamp on the one that works is 04/05/2006
The one that doesnt work is 27/06/2006

So begs the question....what has changed in the June CTP that stops my service from working?

Any ideas?
Steve


Again...the brick wall.
I added in the new CTP dll's to my project that works and it still works.

If i add the old dll's into my not working project...i dont get error 500, but i do get a popup error when trying to change the selection of parent ddl...(eventvalidation error) and no, nothing is bound to the Drop down.

:-(

Steve


sorted it!!!!

I was missing stuff from the web.config file !!!

Well thats two hours of my life gone!!!

Steve


OK...new error now. i seem to be speaking to myself here but if anyone does join in maybe they can help.

The drop down is not binding fine...problem is when i try and postback (with button) i get a postback validation error (there are a few posts on here with no clear answer, none regarding the CDD control though)...anyway, so i turn of validation and the value in the second drop down list has nothing...it should be an number (as id for the text on display...nothing odd there).

I have tried

protectedoverridevoid Render(HtmlTextWriter writer)
{
ClientScript.RegisterForEventValidation(this.UniqueID);
base.Render(writer);
}

but this has no affect.

Steve


i was a touch hasty with my previous post...there is a value in the selectedvalue property....however i was checked that selectedindex > 0...even though it was, it wasnt (if that makes sense - the debugger says 0)...however i got round this withstring.IsNullOrEmpty(ddl.SelectedValue)

But now i have to have eventvalidation off.

What are the implications of this...surely this isnt correct? I must be able to have it turned on...not sure what i does but feel like i'm missing out!!!!!!

Anybody?

Steve


Seee http://forums.asp.net/thread/1293293.aspx #20

Event Validation just makes sure the values you posted from your dropdown are valid values you populated it with. But seeing as the cascading dropdown populates from script, this wont/cant work and if you need to, validate the values on the server (its a security thing)

CascadingDropDowns from bad to worse...

I was getting a [Method Error 500] on a DropDown and was combing through the posts trying to find a solution. I stripped my code down to two simple DropDowns with CascadingDropDown controls attached to them. I was able to get the top level control to populate correctly but was still getting the Eror 500 on my child DropDown. One of the posts I saw suggested making my Web Service methods Shared (I'm using VB). I tried that and now my original DropDown stopped populating at. The Web Service code isn't being reached at all. I tried removing the Shared designation from my methods but the problem has not gone away. I have cleared my IE cache and completely recreated the project. Still, I can't get a single DropDown to populate usnig a Cascading DropDown and a WebService.Here's my aspx markup:

Here's the code in my WebService: _ _ _ _Public Class Locations Inherits System.Web.Services.WebService Private Shared ConnString As String = ConfigurationManager.ConnectionStrings("Inventory").ToString() Private Shared SqlCN As New SqlConnection(ConnString) _ _ Public Shared Function GetLocations() As CascadingDropDownNameValue() Try Dim Ds As DataSet = GetLocationDs() Ds.Tables(0).DefaultView.Sort = "Text ASC" Dim Values As New List(Of CascadingDropDownNameValue) For Each Dr As DataRow In Ds.Tables(0).DefaultView.Table.Rows Values.Add(New CascadingDropDownNameValue(Dr("Text").ToString(), Dr("Value").ToString())) Next Return Values.ToArray() Catch ex As Exception Dim newEx As Exception = ex Return Nothing End Try End Function Private Shared Function GetLocationDs() As DataSet Try Dim SqlCmd As SqlCommand = SqlCN.CreateCommand() Dim PTextColumn As New SqlParameter() Dim PValueColumn As New SqlParameter() Dim PTableName As New SqlParameter() Dim SqlDA As SqlDataAdapter = New SqlDataAdapter() Dim DropDownDS As DataSet = New DataSet() Dim I As Integer = 0 With PTextColumn .DbType = DbType.String .ParameterName = "@dotnet.itags.org.TextColumn" .Value = "Location" End With With PValueColumn .DbType = DbType.String .ParameterName = "@dotnet.itags.org.ValueColumn" .Value = "Location" End With With PTableName .DbType = DbType.String .ParameterName = "@dotnet.itags.org.TableName" .Value = "HE_Locations" End With With SqlCmd .CommandType = CommandType.StoredProcedure .CommandText = "usp_GetDropDownValues" .Parameters.Add(PTextColumn) .Parameters.Add(PValueColumn) .Parameters.Add(PTableName) End With SqlDA.SelectCommand = SqlCmd If SqlCN.State <> ConnectionState.Closed Then SqlCN.Close() End If SqlCN.Open() SqlDA.Fill(DropDownDS, "Values") Return DropDownDS Catch ex As Exception Throw New DataException("GetDropDownValues failed.", ex) Return Nothing Finally SqlCN.Close() End Try End FunctionEnd ClassIf anyone has any ideas, I would sure like to hear them. I'm about ready to pull out my AJAX manual and roll my own. I have lost a whole day on this. Even if I get my original DropDown working I still have the ubiquitous Method Error 500 to deal with.Btw, the code in my Catch block was simply a place to put a breakpoint for debugging so I could read exception mesage if there was one. There wasn't.Thanks!

Well, that didn't come out very well, did it?

Actually, nevermind. For some reason, after using the I.E. Devloper Toolbar, scripting in I.E. was disabled. I also figured out my Method Error 500 problem. I realize now that the parameters in the method signature have to match the example exactly - even the case. I assumed that wouldn't matter since I'm using VB.

Thanks.

Saturday, March 24, 2012

CascadingDropDownList?????? :(

My project requirement says we want to use CascadingDropDown, but we dont want to create the webservice. We just want to create a public method .
Any one has an idea of how to do this.

Does any one have the answer?
Any Answers???

CascadingDropdownList [Method Error 500]

Still trying to get these dropdowns to work. I have created a page with a single ddl that should be populated from the web service and has no parents but I still get the [method error 500] as the values, what am I mising here?

ddl.aspx

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" %>
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@dotnet.itags.org. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!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="ScriptManager1" runat="server" EnablePartialRendering="true" >
</asp:ScriptManager>

<asp:DropDownList ID="Region" runat="server" >
</asp:DropDownList>

<cc1:CascadingDropDown
Category="Region"
Enabled="true"
PromptText="Please work..."
ID="CascadingDropDown2"
TargetControlID="Region"
ServiceMethod="GetCountries"
ServicePath="CountriesByRegion.asmx"
runat="server">
</cc1:CascadingDropDown>

</form>
</body>
</html>

CountriesByRegion.asmx

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports PFCEnergy.Refining.Country.Business
Imports System.Data
Imports AjaxControlToolkit

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CountriesByRegion
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Shared Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim values As New _
System.Collections.Generic.List( _
Of AjaxControlToolkit.CascadingDropDownNameValue)

values.Add(New CascadingDropDownNameValue("foo", "bar"))
values.Add(New CascadingDropDownNameValue("bar", "foo"))
Return values.ToArray
End Function

End Class

Hi,

I too get the same error . Have you sorted the problem ?

Pls help if its working for u .

Thanks.


Yeah got it working, I added the bold and removed the struck through. Good luck.

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports System.Data
Imports AjaxControlToolkit

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CountriesByRegion
Inherits System.Web.Services.WebService

<WebMethod()> _
PublicShared Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim values As New _
System.Collections.Generic.List( _
Of AjaxControlToolkit.CascadingDropDownNameValue)

values.Add(New CascadingDropDownNameValue("foo", "bar"))
values.Add(New CascadingDropDownNameValue("bar", "foo"))
Return values.ToArray
End Function

End Class


Hi,

Iam not using list as u did in web method, So i thinkImports System.Collections.Generic is not needed.

Then i am not using Static (C#) in function.

So what would be wrong in my case?

Thanks.



Hi everyone, I had the same problem and after a little tweaking it works!

Here is the tip:

Please make that the database datatype matches the .NET datatype.If you have a different datatype in your database, you should TYPE CAST it to the corresponding .NET type.
string make = (string)dr["Make"];
int makeId = (int)dr["MakeID"];

.NET Framework Type

ADO.NET Database Type

SQL Data Type

String

Varchar

Varchar()

String

Nvarchar

Nvarchar()

String

NChar

Nchar()

String

NText

NText

String

Text

Text

Double

BigInt

Float

DateTime

DateTime

Datetime

DateTime

SmallDateTime

Smalldatetime

Int

Int

Int

Int64

BigInt

Bigint

Int16

SmallInt

smallint

Byte[]

Binary

Binary()

Byte[]

Image

Image

Byte[]

VarBinary

Varbinary()

Byte

TinyInt

Tinyint

Bool

Bit

Bit

Decimal

Decimal

Decimal

Decimal

Money

Money

Decimal

SmallMoney

SmallMoney

Float

Float

Float

Guid

UniqueIdentifier

Uniqueidentifier

Real

Real

Real

CascadingDropDownList - cant handle more than 765 items!

Hello,

My CascadingDropDownList gives me Method 500 error when more than 765 items are returned from the webservice! Is there a way to fix this? Thanks..

Hi,

that's probably related with the limit for the max size of the JSON payload set by ASP.NET AJAX. You can change it in the web.config:

<jsonSerialization maxJsonLength="500" />


this certainly worked! thank you!
Thanks! Helped me alot.
I have tried putting that in every section and it always errors out as unkown element, if someone can help I would really appreciate it!

Hi,

it must be added inside the configuration -> system.web.extensions -> scripting -> webServices section.


Thank you!

Hi,

I have changed the web config maxJsonLength to 1000. But i dont have that many values. First dropdown is giving me a value but on the second dropdown I am getting method error 500. My webservice code is as follows.

Imports

System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml

<WebService(Namespace:=

"http://tempuri.org/")> _
<System.Web.Script.Services.ScriptService()> _

Public

Class MIService
Inherits System.Web.Services.WebService
Shared _DocumentAs XmlDocument
Shared _lockAsNewObject
PublicReadOnlyProperty Document()As XmlDocument
Get
If (_DocumentIsNothing)Then
SyncLock _lock
_Document =New XmlDocument
_Document.Load(HttpContext.Current.Server.MapPath("~/App_Data/MIService.xml"))
EndSyncLock
EndIf
Document = _Document
ExitProperty
EndGet
EndProperty
PublicReadOnlyProperty Hierarchy()AsString()
Get
Dim _HeirarchyAsString() = {"city","zip"}
Return _Heirarchy
EndGet
EndProperty
<WebMethod()> _
PublicFunction GetDropDownContents(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
'Get a dictionary of known category/value pairs
Dim knownCategoryValuesDictionaryAsNew StringDictionary
knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)' Perform a simple query against the data document
Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category)
EndFunction
EndClass

My code for aspx file is:

<%

@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"EnableEventValidation="False"%>
<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
<scriptrunat="server">
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
PublicSharedFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
ReturnNew MIService().GetDropDownContents(knownCategoryValues, category)EndFunction
</script>
</head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server"/>
<div>
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:DropDownListID="DropDownList1"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList2"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList3"runat="server"AutoPostBack="True"Width="200px">
</asp:DropDownList><br/>
<br/>
<asp:LabelID="Label1"runat="server"Width="224px"></asp:Label><br/>
<br/>
<cc1:CascadingDropDownID="CascadingDropDown1"runat="server"Category="city"LoadingText="[loading City...]"PromptText="Please select a city."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList1"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown2"runat="server"Category="zip"LoadingText="[Loading Zip...]"ParentControlID="DropDownList1"PromptText="Please enter zip."ServiceMethod="GetDropDownContentPageMethod"TargetControlID="DropDownList2"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown3"runat="server"Category="county"LoadingText="[loading County..]"ParentControlID="DropDownList2"PromptText="Please select county."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList3"></cc1:CascadingDropDown>
<br/>
<br/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>


Hi,

I have changed the web config maxJsonLength to 1000. But i dont have that many values. First dropdown is giving me a value but on the second dropdown I am getting method error 500. My webservice code is as follows.

Imports

System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml

<WebService(Namespace:=

"http://tempuri.org/")> _
<System.Web.Script.Services.ScriptService()> _

Public

Class MIService
Inherits System.Web.Services.WebService
Shared _DocumentAs XmlDocument
Shared _lockAsNewObject
PublicReadOnlyProperty Document()As XmlDocument
Get
If (_DocumentIsNothing)Then
SyncLock _lock
_Document =New XmlDocument
_Document.Load(HttpContext.Current.Server.MapPath("~/App_Data/MIService.xml"))
EndSyncLock
EndIf
Document = _Document
ExitProperty
EndGet
EndProperty
PublicReadOnlyProperty Hierarchy()AsString()
Get
Dim _HeirarchyAsString() = {"city","zip"}
Return _Heirarchy
EndGet
EndProperty
<WebMethod()> _
PublicFunction GetDropDownContents(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
'Get a dictionary of known category/value pairs
Dim knownCategoryValuesDictionaryAsNew StringDictionary
knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)' Perform a simple query against the data document
Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category)
EndFunction
EndClass

My code for aspx file is:

<%

@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"EnableEventValidation="False"%>
<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
<scriptrunat="server">
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
PublicSharedFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
ReturnNew MIService().GetDropDownContents(knownCategoryValues, category)EndFunction
</script>
</head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server"/>
<div>
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:DropDownListID="DropDownList1"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList2"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList3"runat="server"AutoPostBack="True"Width="200px">
</asp:DropDownList><br/>
<br/>
<asp:LabelID="Label1"runat="server"Width="224px"></asp:Label><br/>
<br/>
<cc1:CascadingDropDownID="CascadingDropDown1"runat="server"Category="city"LoadingText="[loading City...]"PromptText="Please select a city."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList1"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown2"runat="server"Category="zip"LoadingText="[Loading Zip...]"ParentControlID="DropDownList1"PromptText="Please enter zip."ServiceMethod="GetDropDownContentPageMethod"TargetControlID="DropDownList2"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown3"runat="server"Category="county"LoadingText="[loading County..]"ParentControlID="DropDownList2"PromptText="Please select county."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList3"></cc1:CascadingDropDown>
<br/>
<br/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Thank You,

Nepalaya


Hi,

what's the content of the 500? You can useFiddler to examine it.


I hope u get it the way you want, but 765 items in a drop down list isn't very user friendly? Think about screen res?

Maybe test out autocomplete control?

Just giving my view, but if you want 1000 items in a drop down list, go for it :P (I know how annoying it is when people try to divert you from the solution you want, so go for what is best in your app, just throwing out a suggestion)


Hi,

The problem resolved. It was not related with the lenght. Page method was not working so change the service method name to GetDropDownContents and it works.

<

cc1:CascadingDropDownID="CascadingDropDown1"runat="server"Category="city"LoadingText="[loading City...]"PromptText="Please select a city."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList1">
</cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown2"runat="server"Category="zip"LoadingText="[Loading Zip...]"ParentControlID="DropDownList1"PromptText="Please enter zip."ServicePath="MIService.asmx"ServiceMethod="GetDropDownContents"TargetControlID="DropDownList2">
</cc1:CascadingDropDown>

Thanks,

Nepalaya


Hello freinds,

I am not able to fill the cascading drop down using database. Does any one have fill it with the database??

Please help me i am stuck with this problem.

Thaks in advance.


Hi,

I get method error 500 in dropdownlist1 . Iam using WEB SERVICE .

i used <jsonSerializationmaxJsonLength="500" /> in web.config but still i get the error.

Can any one help ?

Thanks

CascadingDropDownList - Am i being a complete tool?

Hey,

Trying to get my head round these CascadingDropDownLists but i am continually returned with a [Method Error 500] error.

This is my code for 'Default.aspx'


<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.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="ScriptManager1" runat="server" />

<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server"
Category="Author"
TargetControlID="DropDownList1"
ServiceMethod="FillMe"
ServicePath="WebService.asmx"
PromptText="Please select a category"
>
</ajaxToolkit:CascadingDropDown>
</form>
</body>
</html>

And my webservice, WebService.asmx, is as follows:

using System;using System.Configuration;using System.Web;using System.Collections;using System.Collections.Generic;using System.Collections.Specialized;using System.Web.Services;using System.Web.Services.Protocols;using AjaxControlToolkit;using System.Data;using System.Data.SqlClient;/// <summary>/// Summary description for WebService/// </summary>[WebService(Namespace ="http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]public class WebService : System.Web.Services.WebService { [System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod] public static CascadingDropDownNameValue[] FillMe(string knownCategoryValues, string category) { string connString = ConfigurationManager.ConnectionStrings["tenderlistDB"].ConnectionString; SqlConnection conn = new SqlConnection(connString); DataTable dt = new DataTable(); string Sql = "SELECT [ID], [Name] FROM tblCategories WHERE ParentID=@dotnet.itags.org.ParentID ORDER BY [Name] ASC"; try { conn.Open(); SqlCommand comm = new SqlCommand(Sql, conn); comm.Parameters.AddWithValue("@dotnet.itags.org.ParentID", "0"); SqlDataAdapter adapt = new SqlDataAdapter(comm); adapt.Fill(dt); } finally { conn.Close(); } List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); for (int i = 0; i < dt.Rows.Count; i++) { CascadingDropDownNameValue CCD = new CascadingDropDownNameValue(); CCD.name = dt.Rows[i]["Name"].ToString(); CCD.value = dt.Rows[i]["ID"].ToString(); values.Add(CCD); }return values.ToArray(); }}

Anyone have an idea as to why it's just not working?

Cheers,

Sean


Most likely you have an exception being thrown in your WebMethod. Set a breakpoint in it and use the site in Debug mode. Step through the WebMethod and see if you are getting an exception. This is usually the case for me. The other thing I have seen is too much information being returned, but I think that is another error number. The Execption will not be returned by the Web Service, so AJAX throws a 500 error up at you.


Thanks for getting back to me.

I've never really used the debug function, but i stuck some breakpoints in the code and hit F5, and it all ran ok.

If i run it in debug mode, instead of Error method 500, i get an Error Method 12031...Could that be anything?

In terms of the SQL, it returns 12 rows when run through Sql Query Analyzer.

Appreciate your help!


Been thinking about this a little over lunch. Have you marked your Web Service and Web methods with AJAX attributes?

The Class should have this attribute:

<System.Web.Script.Services.ScriptService()> _

The Web Method this one:

<System.Web.Script.Services.ScriptMethod()> _

So a method would resemble the following:

<WebMethod()> _

<System.Web.Script.Services.ScriptMethod()> _

PublicFunction GetMarkets(ByVal knownCategoryValuesAsString, _

ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()

Dim kvAs StringDictionary = _

AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

Dim RegionIdAsInteger

IfNot kv.ContainsKey("Region")OrElseNot Int32.TryParse(kv("Region"), RegionId)Then

ReturnNothing

EndIf

Dim lcAsNew LocMarketController

Dim itemListAs LocMarketList = lc.GetLocMarketByRegion(RegionId)

Dim valueAsNew List(Of AjaxControlToolkit.CascadingDropDownNameValue)

ForEach itemAs LocMarketInfoIn itemList

value.Add(New AjaxControlToolkit.CascadingDropDownNameValue(item.Market, item.MarketId))

Next

Return value.ToArray

EndFunction


Hey,

Tried that but still no joy. Starting to get frustrating now hehe, anyone else got any ideas?

Cheers for the help!


Hey,


Just to let you all know i got it working...i rewrote it this morning when i got into work and its all working fine...not sure why though, i have a feeling I wasn't passing through the correct parameters, so when the


'StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);'

line was hit, the method would break!

Thanks for all the help.

CascadingDropDown with a Database, Method Error 405

Hey guys,


I followed the AjaxControlToolki tinstructions on how to create a WebService and specify everything so that it would populate two DropDownLists. The problem is, the first DropDownList has a [Method Error 405] as its only value. If I select it, the second DropDownList is populated with the same.

After checking, rechecking and extensively searching, I haven't found my error. I've read at least a dozen topics on this error but none have helped me.

Here is my code:

App_Code/StateServices.cs:

using System;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
using System.Data;

/// <summary>
/// Summary description for StateServices
/// </summary>[WebService(Namespace ="http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.Web.Script.Services.ScriptService]public class StateServices : System.Web.Services.WebService { GeographicalDelimitationsDB GeoDataSource = new GeographicalDelimitationsDB(); GeographicalDelimitationsDBTableAdapters.CountyInfoTableAdapter GeoCountyInfoTableAdapter = new GeographicalDelimitationsDBTableAdapters.CountyInfoTableAdapter(); GeographicalDelimitationsDBTableAdapters.ZipCodesTableAdapter GeoZipCodesTableAdapter = new GeographicalDelimitationsDBTableAdapters.ZipCodesTableAdapter(); public StateServices() { } [WebMethod] public CascadingDropDownNameValue[] GetCounties(string knownCategoryValues, string category) { GeographicalDelimitationsDB.CountyInfoDataTable counties = GeoCountyInfoTableAdapter.GetData(); List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); foreach (DataRow dr in counties.Rows) { string name = (string)dr["Name"];
int countyID = (int)dr["CountyCode"];

values.Add(new CascadingDropDownNameValue(name, countyID.ToString()));
}

return values.ToArray();
}

[WebMethod]
public CascadingDropDownNameValue[] GetCitiesForCounty(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

int countyID;

if (!kv.ContainsKey("County") || !Int32.TryParse(kv["County"], out countyID))
{
return null;
}

GeographicalDelimitationsDB.ZipCodesDataTable cities = GeoZipCodesTableAdapter.GetDataByCountyID(countyID);

List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

foreach (DataRow dr in cities.Rows)
{
values.Add(new CascadingDropDownNameValue((string)dr["City"], dr["ZIP"].ToString()));
}

return values.ToArray();
}
}

 
index.aspx: 

 <asp:UpdatePanel ID="NavigationUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="ConfigurationContentPart" runat="server" CssClass="module-content">
<h3>County:</h3>
<p>
<asp:DropDownList ID="CountyList" runat="server" onchange="selectCounty(this)" />
</p>
<h3>City:</h3>
<p>
<asp:DropDownList ID="CityList" runat="server" onchange="selectCity(this)" />
</p>
</asp:Panel
<ajaxToolkit:CascadingDropDown ID="CountyCascadingDropDown" runat="server" TargetControlID="CountyList" Category="County" PromptText="Select a County" LoadingText="[Loading...]" ServicePath="StateServices.asmx" ServiceMethod="GetCounties" />
<ajaxToolkit:CascadingDropDown ID="CityCascadingDropDown" runat="server" TargetControlID="CityList" Category="City" PromptText="Select a City" LoadingText="[Loading...]" ServicePath="StateServices.asmx" ServiceMethod="GetCitiesForCounty" ParentControlID="CountyList" /
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>

Bump...

Please help, I'm really stuck!


Does it work without the onchange handlers on the DropDownLists?

Wednesday, March 21, 2012

CascadingDropDown Sample problem, Method Error 500

Hi

I've downloaded the last version of Control Toolkit and I've installed it. When I try to run the WebSampleSite, everything works fine except CascadingDropDown, The first combo says "Method Error 500". Any ideas?

Please help...

to me Method Error 500 is webservices error

try look webservices area..make sure it gets call (you can debug into it)

CascadingDropDown returns [Method Error 12031] after upgrade to 1.0 Beta

After upgrading from the July CTP to 1.0 Beta all my CascadingDropDown's have stoped working. I only get [Method error 12031] in return an all of them. I hade the same problem when implementing them the first time but I then found the answer in thread 1393072 and referenced threads. This time however I am not able to find anything that helps me. I have tried to migrate my July CTP projekt to a new empty 1.0 Beta project but it doesn't help. Have anyone else hade the same problem?

I am grateful for any suggestions and tips!!

Have you made sure to decorate your service class with this attribute?

[Microsoft.Web.Script.Services.ScriptService()]
public class MyService : WebService
{
...
}


Thanks allot!

Now i works just fine. One can wonder why that line isn't in the walkthrough for CascadingDropDown!


Thanks a lot for that! That's been bugging me all morning. Although I didn't have [Method Error 12031], I had [Method Error 500], this solution still worked for me. It really should be in the walkthrough
I Agree! This should be added RIGHT AWAY!!!

Hey Guys,

Actually there is some documentation and I'll point you to where I found most of my upgrade info. Garbin's recent post on his blog has three links to some very vital information.

http://aspadvice.com/blogs/garbin/archive/2006/10/20/MS-AJAX-v1.0-Beta-and-Ajax-Control-Toolkit-released_2100_.aspx

The CTP-to-Beta whitepaper is where I found the not for adding the ScriptService attribute.

Hope this helps.


The method error 12030 still appears for me when I use the CTP and the specified attribute.

Regards

Vinit


Did you change the return type of your methods that populate your drop downs to return an array of AjaxControlToolkit.CascadingDropDownNameValue objects?

All web methods for child drop downs must have a signature that conforms to the following:

[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDataForMyChildDropDown(string knownCategoryValues, string category)

You can find this in the CTP-to-Beta whitepaper I believe.


Hiya.

Had the same problem and finally found out why. None of the other things suggested worked. Thanks to Steve Clements for that one... http://geekswithblogs.net/steveclements/archive/2006/10/23/94893.aspx

The web service class either needs

[Microsoft.Web.Script.Services.ScriptService]

or

using Microsoft.Web.Script.Services;

namespace Clm.Web.Services

{

[ScriptService]

publicclassFoo


Your most welcome :)

Steve


Same problem, but using only pagemethods...

What changes do I need to get it working?


Can you post some code?
http://forums.asp.net/thread/1486194.aspx

Hi,

I've run into the same error. However, when I change the line in the webservice.vb file from:

<System.Web.Script.Services.ScriptService ()>'

to:

<Microsoft.Web.Script.Serices.ScriptService ()
I get the error 'Type Microsoft.Web.Script.Serices.ScriptService' is not defined'

The whole "snippet":

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class CarsService
Inherits System.Web.Services.WebService

Shared _DocumentAs XmlDocument
Shared _lockAs New Object

I'd appreciate any suggestions.
Thanks!

CascadingDropDown Problem

Hi All

I'm using the latest release of the toolkit. I'm building a CascadingDropDown and am getting a 12030 method error when I use a remote service (rather than have the service in the same project).

<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="ddlMake" Category="Make" PromptText="Please select a make" LoadingText="[Loading makes...]" ServicePath="~/../CarServiceLocal/CarService.asmx" ServiceMethod="GetDropDownContents"/>

If I set the Service path to a local asmx file it works fine ServicePath="CarService.asmx"

But if I change it to be a remote service

ServicePath="~/../CarServiceLocal/CarService.asmx"

or

ServicePath="http://localhost/CarServiceLocal/CarService.asmx"

Then I get the 12030 method error.

Does anyone have any ideas?

Cheers


Craig

The CDD sample page uses the ~ syntax, so I'm reasonably confident it works in general. Your use of it with ".." makes me wonder if it works like you think it does. I'd say to double-check that the final path that gets used is correct.

CascadingDropDown Problem

Hello everyone,

I'll try to keep it simple and brief. This is another "[Method Error 500]" problem. I looked through all previous posts, but couldn't figure out the solution to my problem.

I'm using AJAX 1.0 RC and the latest version of the Control Toolkit (downloaded yesterday).
I have 3 dropdownlists. Here's how it goes:

1) I select something from DDL1 (DDL2 becomes populated)
2) I select something from DDL2 (DDL3 becomes populated)

until this point everything is OK. BUT, in DDL2, there is aparticularitem that when I select it, DDL3 says "Method Error 500". Other than that particular item, it all works fine.

Notes:
1) My Webservice declaration has the attribute[System.Web.Script.Services.ScriptService()]
2) I debugged the code, the results for this particular problem are returned from the database just fine, no exceptions, no problems.

Any ideas, tips?

Thanks!

This, perhaps:http://ajax.asp.net/docs/mref/P_System_Web_Script_Serialization_JavaScriptSerializer_MaxJsonLength.aspx

Yes! Thanks

(http://forums.asp.net/thread/1553105.aspx)

CascadingDropDown Method Error 500 Bug

Hello,

I have been trying out CascadingDropDown for few weeks now. One thing that I specifically noticed is that all Cascadingdropdowns works fine with the webservice. But the problem happens if number of rows returned to CascadingDropDown is more than 906, then I get method error 500.


Is 907 a magic number OR CascadingDropDowns cannot carry more data? I debugged the webservice and the array that it returns looks ok even if has more than 906 records. Just the CascadingDropDown doesn't like if get more than some specific amount/ number of records

Is there any solution or workaround?

------

Here's my webservice method

 <WebMethod()> _ Public Function GetPages(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue() Dim Values As List(Of CascadingDropDownNameValue) = New List(Of CascadingDropDownNameValue) Dim Kv As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues) Dim Ds As DataSet Ds = DbImageInfo.ExecuteQuery("SELECT Page FROM ImageInfo WHERE County=" & Kv("County") & " AND Type='" & Kv("Docket") & "' AND Book='" & Kv("Book") & "' ORDER BY Page") For Each Dr As DataRow In Ds.Tables(0).Rows Values.Add(New CascadingDropDownNameValue(Dr("Page").ToString, PadVariableLength(Dr("Page").ToString)) Next Return Values.ToArray End Function

-------

And here's my asp.net tags

 <ajaxToolkit:CascadingDropDown ID="CascadingDropDown4" runat="server" TargetControlID="DdlPage" Category="Page" PromptText="Page..." LoadingText="[Busy...]" ServicePath="WebService.asmx" ServiceMethod="GetPages" ParentControlID="DdlBook"/>

hello,
I have exactly the same problem. Have you found any solution?
Many thanks

CascadingDropDown Method Error 500 ?

Hello!
I looked through lots of solutions to this problem on this forum but nothing helps - I still get Method Error 500 in drop down list.
Here's the code I use:

LocationService.asmx
----------

[WebService(Namespace =http://www.lgcon.ca/)]
[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]
publicclassServiceLocation : System.Web.Services.WebService
{

[WebMethod]
[System.Web.Script.Services.ScriptMethod]
publicCascadingDropDownNameValue[] GetCountry(string knownCategoryValues,string category)
{
List<CascadingDropDownNameValue> values =newList<CascadingDropDownNameValue>();

values.Add(newCascadingDropDownNameValue("one","one"));
values.Add(newCascadingDropDownNameValue("two","two",true));

return values.ToArray();
}

}

ASPX page:
------
<asp:DropDownListID="ddlCountry"runat="server"/>
<cc1:CascadingDropDownID="cddCountry"runat="server"TargetControlID="ddlCountry"Category="Country"PromptText="Select a country"ServicePath="~/modules/location/ServiceLocation.asmx"ServiceMethod="GetCountry"/>

What am I doing wrong?

Thanks for help!

ok nevermind .. got it working .. just had to add "[System.Web.Script.Services.ScriptService]" before class declaration :)

CascadingDropDown method error 500

Hi,

I've created a new project following the video found here :http://www.asp.net/learn/ajax-videos/video-77.aspx

My code is the same as in the demo, but when I run the website, I have the "method error 500" in each dropdownlist instead of the makes, models and colors...

Does anyone know what this error code means ?

Thanks for your help.

Hi Dpin,

10.5 Server Error 5xx
Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents should display any included entity to the user. These response codes are applicable to any request method.

10.5.1 500 Internal Server Error
The server encountered an unexpected condition which prevented it from fulfilling the request.

To resovle the kind of problem, we suggest that you should first check whether your WebService works fine or not. Then check the Control settings. If all these are ok, but your application doesn't work properly. Please add break points to your WebService and debug it step-by-step. Here is theuseful information. Please pay special attention to my last reply.

I hope this help.

Best regards,

Jonathan

CascadingDropDown Method error 500

Hi,

I have a problem with cascading drop down. I tried to reproduce the video tutorial with countries and states instead of cars. I can manage to get the first one to work but the second one give me the [Method error 500]. I don't know where I made a mistake.

I really hope someone can answer me.

FMaheu

************** Web service CountryService.asmx *****Imports System.WebImports System.Web.ServicesImports System.Web.Services.ProtocolsImports System.Xml<WebService(Namespace:="http://tempuri.org/")> _<System.Web.Script.Services.ScriptService()> _Public Class CountryServiceInherits System.Web.Services.WebServiceShared _DocumentAs XmlDocumentShared _lockAs New Object Public ReadOnly Property Document()As XmlDocumentGet If (_DocumentIs Nothing)Then SyncLock _lock _Document =New XmlDocument _Document.Load(HttpContext.Current.Server.MapPath("~/App_Data/Copy of countries.xml"))End SyncLock End If Document = _DocumentExit Property End Get End Property Public ReadOnly Property Hierarchy()As String()Get Dim _HierarchyAs String() = {"country","state"}Return _HierarchyEnd Get End Property <WebMethod()> _Public Function GetDropDownContents(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As AjaxControlToolkit.CascadingDropDownNameValue()Dim knownCategoryValuesDictionaryAs New StringDictionary knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category)End FunctionEnd Class************************ aspx file ********<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title> <script runat="server"> <System.Web.Services.WebMethod()> _ <System.Web.Script.Services.ScriptMethod()> _Public Shared Function GetDropDownContentsPageMethod(ByVal knowCategoryValuesAs String,ByVal categoryAs String)As AjaxControlToolkit.CascadingDropDownNameValue()Return New CountryService().GetDropDownContents(knowCategoryValues, category)End Function </script></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> </div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server" Width="213px"> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" Width="212px"> </asp:DropDownList> <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="country" LoadingText="[Loading countries ...]" ServiceMethod="GetDropDownContents" ServicePath="CountryService.asmx" PromptText="Please select a country" TargetControlID="DropDownList1"> </cc1:CascadingDropDown> <cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" ParentControlID="DropDownList1" Category="state" LoadingText="[Loading states ...]" ServiceMethod="GetDropDownContentsPageMethod" PromptText="Please select a state" TargetControlID="DropDownList2"> </cc1:CascadingDropDown> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

Nevermind I kinda got it to work somehow ...Confused

Hi FMaheu,

I am having same problem as you mentioned. First dropdown works but second dropdown is giving me error "Method Error 500". Would you please let me know what change that you made on your code to fix that error.

Thank You,

Nepalaya


Hi nepalaya,

Sorry for the delay, I'm very busy these days. So instead of using a page method I used the method in my countryservice.asmx. Something seemed to be wrong with my page method and since I could just use the same method as the first cascading drop down ...

I have also read in other threads that the control could only support a limited number of objects. That could be modified in the web.config file.

I hope this helps

FMaheu

P.S. I posted my ASP.NET Code in case in would help you understand better.

1 <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="country" LoadingText="[Chargement des pays ...]"2 ServiceMethod="GetDropDownContents" ServicePath="CountryService.asmx" PromptText="Sélectionner un pays" TargetControlID="DropDownList1">3 </cc1:CascadingDropDown>4 <cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" ParentControlID="DropDownList1" Category="state" LoadingText="[Chargement des états/porvinces ...]"5 ServiceMethod="GetDropDownContents" PromptText="Sélectionner un état/province" TargetControlID="DropDownList2" ServicePath="CountryService.asmx">6 </cc1:CascadingDropDown>7

Thank You very much.

Yes it works.

Thanks,

Mani


I have my code identical to yours and I am getting a method error 12030. Any ideas?

From my search, that error is given to you when your aspx page cannot reach the web service. Is your service external to your web project? If so try copy it inside your web project. It seems calling an external web service doesn't work very well with CascadingDropDown.

Hope this helps a little


my web service (.asmx file) is in my web project. It is weird, sometimes I get method error 500 errors and sometimes I get method error 12030 errors. There isn't a pattern that I can find.
Most likely the web service isn't defined or hooked up properly. The ASP.NET AJAX infrastructure is pretty unforgiving here, so make sure everything is as it should be.

CascadingDropDown Method error 500

I have a couple of CascadingDropDown controls on an ASP.NET page and am filling them from a code behind function that makes a call to a SQL Server 2005 database. My problem is that sometimes I receive a 'Method error 500' when filling the second dropdownlist based on a parent control. I am concatenating three fields together and I can mix and match 2 of them, but when I use all three, I consistently get the error.

Example "Select StoreCode + ' ' + City + ' ' State as Name From Table".

Is there a data size limit with using this control?

Also, I am able to bind the same data to a dropdownlist not used in AJAX.

Thanks in Advanced,

Marc


I am encountering a similar problem with some CascadingDropDowns that help define someone's location. Whn I gt tothe City level, sometimes I get a 'Method Error 500' and sometimes I do not.

Your question "Is there a data size limit with using this control?" got me experimenting, and my results suggested that indeed there was a correlation between the error and the amount of data being returned.

So I installed IEInspector and fond that indeed, requests that return a lot of data are creating a problem. This is one of the responses I am getting:

{"Message":"Maximum length exceeded.","StackTrace":" at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n
at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
 
My next step is to use Reflctr to look at the code for System.Web.Script.Services.RestHandler.InvokeMethod and see what I discover.
 
Thanks for the data length suggestion!
 

Ken, thanks for the investigative work. Can you please keep me updated as to what you find?

I too will continue to debug this issue and will report any findings to this thread.

Thanks in advance,

Marc


Eureka!

Stepping thru the AJAX source code was tiring but informative.

In any event, here is my solution (if your underlying issue is different, YMMV).

I was hitting a size limit in the JSON conversion stuff, which fortunately can be customized without recompiling the code.

When returning custom objects (like the arrays returned by the CascadingDropDown web methods), the objects are serialized using object names, including their namespace. While my collections were only a few thousand items in length, the unfortunate choice of the long-winded namespace 'AjaxControlToolkit' and class name 'CascadingDropDownNameValue' results in ridiculous object bloat and blows out the default JSON string size by adding the long object name to every single object.

For example, a single City in my array of around 4000 of them is being returned like this:

"__type":"AjaxControlToolkit.CascadingDropDownNameValue","name":"Abanda","value":"2728903","isDefaultValue":false},{"

IMHO it would be much more efficient (and give us programmers less gray hairs!) if shorter names were used, like:

"__type":"AjaxCT.CDDNV","n":"Abanda","v":"2728903","def":false},{"

Or even better, instead of returning an array of objects, return a single object (thus avoiding the namespace.classname overhead in each array element) that contains a string with the data in it. That is exactly what I did in my earlier implementation using Michael Schwartz's AJAX.NET and my own custom code.

In any event, adding the following to my Web.Config solved my issues (so far):

<

system.web.extensions>
<scripting>
<webServices>
<jsonSerializationmaxJsonLength="5000000" />
</webServices>
</scripting>
</system.web.extensions>This link describes Web.Config settings for AJAX:

http://ajax.asp.net/docs/ConfiguringASPNETAJAX.aspx#microsoftweb

This forum thread was also helpful:

http://forums.asp.net/thread/1634922.aspx