Saturday, March 24, 2012

CascadingDropDownList problem !

Hi there, I'm in trouble with cascadingDropDownList extender.

I use webMethod to make connection to a SQL database, actually methods work fine and get results in XML form in test page. However, when I make call from the cascadingDropDownLists at the .aspx page, It only gets a "Method error 500"

Here is the code

---.ASPX---

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"EnableEventValidation="false" %>

<%@dotnet.itags.org.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="atlasToolkit" %>

<!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>

</head>

<body>

<formid="form1"runat="server">

<atlas:ScriptManagerID="ScriptManager1"runat="server"/>

<div>

<asp:DropDownListID="DropDownList1"runat="server">

</asp:DropDownList>

<asp:DropDownListID="DropDownList2"runat="server">

</asp:DropDownList>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="DropDownList1"

Category="MarkaTitle"

ServicePath="http://localhost:3631/CDDWebService/Service.asmx"

LoadingText="Please Wait..."

PromptText="Select a Marka..."

ServiceMethod="getMarka">

</atlasToolkit:CascadingDropDownProperties>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="DropDownList2"

Category="ModelTitle"

ServicePath="http://localhost:3631/CDDWebService/Service.asmx"

ParentControlID="DropDownList1"

ServiceMethod="getModel"

PromptText="Select Model..."

LoadingText="Please Wait...">

</atlasToolkit:CascadingDropDownProperties>

</atlasToolkit:CascadingDropDown>

</div>

</form>

<scripttype="text/xml-script">

<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

<references>

</references>

<components>

</components>

</page>

</script>

</body>

</html>

/---.ASPX---

--WebService Codes--

using System;

using System.Web;

using System.Web.Services;

using System.Configuration;

using System.Web.Services.Protocols;

using AtlasControlToolkit;

using System.Collections;

using System.Collections.Generic;

using System.Collections.Specialized;

using System.Data;

using System.Data.SqlClient;

[WebService(Namespace ="http://Boss.com.tr/",Name="CDDWS")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

publicclassService : System.Web.Services.WebService

{

string myConnectionString =ConfigurationManager.ConnectionStrings["VehiclesConnectionString"].ToString();

public Service () {

//Uncomment the following line if using designed components

//InitializeComponent();

}

[WebMethod]

publicCascadingDropDownNameValue[] getMarka(string knownCategoryValues,string category)

{

SqlConnection dbConnection =newSqlConnection(myConnectionString);

SqlDataAdapter myAdapter =newSqlDataAdapter("select * from MarkaTbl", dbConnection);

DataTable myTable =newDataTable();

try

{

myAdapter.Fill(myTable);

}

catch (Exception ex)

{

//throw ArgumentException("not valid");

}

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

foreach (DataRow drin myTable.Rows)

{

values.Add(newCascadingDropDownNameValue((string)dr["MarkaTitle"],dr["MarkaID"].ToString()));

}

return values.ToArray();

}

[WebMethod]

publicCascadingDropDownNameValue[] getModel(string knownCategoryValues,string category)

{

SqlConnection dbConnection =newSqlConnection(myConnectionString);

SqlDataAdapter myAdapter =newSqlDataAdapter("select * from ModelTbl", dbConnection);

DataTable myTable =newDataTable();

try

{

myAdapter.Fill(myTable);

}

catch (Exception ex)

{

}

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

foreach (DataRow drin myTable.Rows)

{

values.Add(newCascadingDropDownNameValue((string)dr["ModelTitle"], dr["ModelID"].ToString()));

}

return values.ToArray();

}

}

/--WebService Codes--

One more question; I couldn't understand exactly what is "category", and what it is stands for. I considered it is as fieldName of at the database :)

Thanks for any help ...

At least, can someone tell me what is "category" in CascadingDropDown extender ?

Hi BossDida,

You're getting a message returned by the ASP.NET AJAX Extensions indicating "there was a problem with your web service." I'd take a look at the CascadingDropDown.aspx sample page to see how what you're doing differs from it.

Also, the category (as described in the CascadingDropDown sample page) is used to indicate to the web service which drop down is asking for data (because you can have all your drop downs hit the same webmethod if you wanted).

Thanks,
Ted

No comments:

Post a Comment