Showing posts with label methods. Show all posts
Showing posts with label methods. Show all posts

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

Cascadingdropdown working with web methods

Hi,

I am using the Cascadingdropdown as below

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

<atlasToolkit:CascadingDropDownPropertiesTargetControlID="DropDownList1"Category="Principal"PromptText="Please select Principal"LoadingText="[Loading Principals...]"ServiceMethod="GetDropDownContentsPageMethod"/>

<atlasToolkit:CascadingDropDownPropertiesTargetControlID="DropDownList2"Category="MessageType"PromptText="Please select message type"LoadingText="[Loading Message Types...]"ServicePath=""ServiceMethod="GetDropDownContents1"ParentControlID="DropDownList1"/>

</atlasToolkit:CascadingDropDown>

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

</asp:DropDownList>

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

And the code behind is

<WebMethod()> _

PublicFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AtlasControlToolkit.CascadingDropDownNameValue()

Dim lobjDALAs VOSS.Integrations.Web.DataAccess.XmlAdmin

Try

lobjDAL =New VOSS.Integrations.Web.DataAccess.XmlAdmin

Return lobjDAL.GetRegions(knownCategoryValues, category)

Catch exAs Exception

ReturnNothing

Finally

lobjDAL =Nothing

EndTry

EndFunction

<WebMethod()> _

PublicFunction GetDropDownContents1(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AtlasControlToolkit.CascadingDropDownNameValue()

Dim lobjDALAs VOSS.Integrations.Web.DataAccess.XmlAdmin

Try

lobjDAL =New VOSS.Integrations.Web.DataAccess.XmlAdmin

Return lobjDAL.GetDropDownContents2(knownCategoryValues, category)

Catch exAs Exception

ReturnNothing

Finally

lobjDAL =Nothing

EndTry

ReturnNothing

EndFunction

Now the first function works and retrieves the values, but the second function does not. I am not using a web service. Do I need to always use a webservice for this. Can both the methods not pick values directly from db?

Pleae assist

Regards

Raj

Hi Raj,

You should check outFAQ Item #20.

Thanks,
Ted

Wednesday, March 21, 2012

CascadingDropDown not populating

Hi

I'm trying to use the CascadingDropDown with a database in VB, using page methods.

My three DropDownLists are drpProject, drpFixFor and drpFixForSub. The drpProject control is populated fine when the page loads; and I'd expect the drpFixFor control to be populated when drpProject is changed, however, this is not happening.

The drpFixFor control is being enabled, but not populated - my "GetFixForList" function doesn't appear to be calledat all. (I put a breakpoint in it, and the breakpoint isn't hit.)

Interestingly, if I remove ParentControlID="drpProject" from drpFixFor's extender, the function is called as expected when the page loads.

My aspx page is:

<%

@dotnet.itags.org.PageLanguage="VB"MasterPageFile="~/MasterPage.master"AutoEventWireup="false"CodeFile="Test.aspx.vb"Inherits="Test"Title="" %>

<%

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

<

asp:ContentID="Content1"ContentPlaceHolderID="cphBody"runat="Server">
<table> <tr> <tdstyle="width: 100px">Project:</td> <td><asp:DropDownListID="drpProject"runat="server"/></td> </tr> <tr> <tdstyle="width: 100px">Fix For:</td> <td><asp:DropDownListID="drpFixFor"runat="server"/></td> </tr> <tr> <tdstyle="width: 100px">Fix For Sub:</td> <td><asp:DropDownListID="drpFixForSub"runat="server"/></td> </tr></table><atlasToolkit:CascadingDropDownID="CascadingDropDown1"runat="server"> <atlasToolkit:CascadingDropDownPropertiesTargetControlID="drpProject"Category="Project"PromptText="(Select One)" ServiceMethod="GetProjectList"/> <atlasToolkit:CascadingDropDownPropertiesTargetControlID="drpFixFor"Category="FixFor"PromptText="(Select One)"ParentControlID="drpProject"ServiceMethod="GetFixForList"/> <atlasToolkit:CascadingDropDownPropertiesTargetControlID="drpFixForSub"Category="FixForSub"PromptText="(Select One)"ParentControlID="drpFixFor"ServiceMethod="GetFixForSubList"/></atlasToolkit:CascadingDropDown>

</

asp:Content>

And my Code Behind page is:

Imports

AtlasControlToolkit

Imports

System.Web.Services

Partial

Class Test Inherits System.Web.UI.Page

<WebMethod()> _

PublicFunction GetProjectList(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue() Dim valuesAsNew Generic.List(Of CascadingDropDownNameValue) ForEach myProjectAs ProjectIn Project.GetList

values.Add(

New CascadingDropDownNameValue(myProject.Name, myProject.ID)) Next Return values.ToArray EndFunction

<WebMethod()> _

PublicFunction GetFixForList(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue() Dim valuesAsNew Generic.List(Of CascadingDropDownNameValue) ' Hardcode to Project "2" for debugging ForEach myFixForAs FixForIn FixFor.GetList(2)

values.Add(

New CascadingDropDownNameValue(myFixFor.Name, myFixFor.ID)) Next Return values.ToArray EndFunction

End

Class

Note: "Project" and "FixFor" are objects defined in my App_Code folder, and their "GetList" functions return data from the SQL database.

Any ideas?

Thanks,
Andrew

I am also facing some issues with the cascadingdropdown extender, my question is that what if my database schema is such that i dont have ID for the fields in the drop downs, cant i fetch the value in the second drop down with the string value in the first drop down. As i understand this, ID seems to be added mandatorily in this extender.

-Pratibha


I don't see anything wrong with your code - what happens if you change all three service method's to call the one that's workng? Does it get called then?

Pratibha - I don't understand your question. ID isn't added by the extender at all - you can put whatever you want into the value field of the CascadingDropDownNameValue.


hey shawn, now i get it..hadnt looked carefully through the tool kit code earlier. It makes sense now and the cascadingdropdown works perfectly :)
Cool!

Hi

I've tried setting all three service methods to call GetProjectList, and still no luck - the function's called once when the page is loaded to populate the first DropDown, and not called for the others.

Thanks,
Andrew


To fix this, you need to add EnableEventValidation="false" to your Page directive. This should be a FAQ for CascadingDropDown, but basically ASP.NET tries to make sure that postbacks don't contain stuff they shouldn't based on what it knows about the page it sent down. Well, CDD is all about sending back data that wasn't in the page to begin with, so this feature needs to be disabled for pages that use it.

That's the good news. :) The bad news (or better news depending on how you see it) is that this should have been easier to debug. CDD tries to populate the list with error details when an error occurs (see _onMethodError), but it doesn't because a change some time ago to use name/value pairs for the data type wasn't applied to the error methods. I've logged this for fixing in the next release.

But for now, your issue should be trivially solvable by flipping EnableEventValidation as I note above.

Thanks!


Fantastic - that did the job!

Thanks
Andrew


nice1 David,

that had really thrown me, thought it was a vb.net thing. the debugging experience on this could definitely be improved on but at least it's in the forums.

thanks

I've been trying to get this example to work so as I can use similar in my own pet project.

Would anyone be kind enough to tell\show me how to create the "Projects" and "FixFor" objects which are defined in the App_Code folder.

I'm getting errors on this line

ForEach myProjectAs ProjectIn Project.GetData

How do I define Project in the TableAdapter?

Rgds

DOShea


Hi,

My parent dropdown itself is not population. I addedEnableEventValidation="false" in page tag. Still no luck.

If i work in " atlas web project", I am able sccess with cascading dropdown. But if i try to do with existing project, i am not able to. No error but first dropdown itself not populating.

I added in web.config

<

pages>

<

controls>

<

addnamespace="Microsoft.Web.UI"assembly="Microsoft.Web.Atlas"tagPrefix="atlas"/>

<

addnamespace="Microsoft.Web.UI.Controls"assembly="Microsoft.Web.Atlas"tagPrefix="atlas"/>

</

controls>

...

</

pages>

This is my aspx page code:

<%

@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"EnableEventValidation="false" %>

<%

@.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="atlasToolkit" %>
<formid="form1"runat="server"><atlas:ScriptManagerID="ScriptManager1"runat="server"/><div><asp:DropDownListID="DropDownList1"runat="server"></asp:DropDownList><asp:DropDownListID="DropDownList2"runat="server"></asp:DropDownList></div><atlasToolkit:CascadingDropDownID="CascadingDropDown1"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="DropDownList1"Category="Make"PromptText="Please select a make"ServiceMethod="GetDropDownContentsPageMethod"/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="DropDownList2"Category="Model"PromptText="Please select a model"ServicePath="CarService.asmx"ServiceMethod="GetProductGroups"ParentControlID="DropDownList1"/></atlasToolkit:CascadingDropDown></form>

.Vb File:

<WebMethod()> _

PublicFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue()

Dim valuesAs List(Of CascadingDropDownNameValue) =New List(Of CascadingDropDownNameValue)

values.Add(

New CascadingDropDownNameValue("A","1"))

values.Add(

New CascadingDropDownNameValue("B","2"))

values.Add(

New CascadingDropDownNameValue("C","3"))Return values.ToArrayEndFunction

My WebService (CarService.vb):

<WebMethod()> _

PublicFunction GetProductGroups(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue()Dim kvAs StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)Dim valuesAs List(Of CascadingDropDownNameValue) =New List(Of CascadingDropDownNameValue)Dim ProvinceIdAsIntegerIf (kv.ContainsKey("Make")And Int32.TryParse(kv("Make"), ProvinceId))ThenIf ProvinceId = 1Then

values.Add(

New CascadingDropDownNameValue("a","1"))ElseIf ProvinceId = 2Then

values.Add(

New CascadingDropDownNameValue("b","1"))EndIfEndIfReturn values.ToArrayEndFunction

Any help is highlyAppreciated.

Regards

kant.


My reply from the private email about this issue:

"The web.config for an Atlas has additional settings that aren't present in a default web.config. It sounds like you need to add one or more of those settings to your site's web.config. You might find the windiff utility helpful in identifying the changes. Hope this helps!"


Thanks David. I am able to solve by adding aditional attributes.

I have another prob with in the same page. I added a gridview to that page having Edit & Delete buttons.

When ever my page is postback(by clicking button or by grid events ) , it's refreshing twice. Any Idea?

I am usingCollapsiblePanel, CascadingDropDownin that page.

kindly reply me if you come across this probulem.

Regards

Kant.


Hi,

This is my scenario.

In production server (win2003 with IIS 6.0, asp.net 2.0 and asp.net 1.1 coexist),
My drop downs appear blank if I try to use web services to provide the data.
If I use built in page methods and I got 'sys' is undefined.

In development pc, (XP with IIS 5.1, asp.net 2.0 and asp.net 1.1 coexist),
Both web services and page methods work without any problem.

Web.config in both machine were identical.

Does anyone have any idea why?

Thanks in advance.

Michael


"Sys undefined" suggests that Atlas itself may not be installed/configured correctly on that server.