Showing posts with label cascading. Show all posts
Showing posts with label cascading. Show all posts

Wednesday, March 28, 2012

Very Weird Problem with Cascading DropDown

After some version updates both in AJAX.NET and Control Toolkit, I found the Cascading DropDown does not work in my project. The appearance is: the DropDown is simply blank. Even the PromptText is not shown up in the page. DropDown is not populated while the web service is working fine. No error reports to me.

But at mean time, the Sample project of Cascading DropDown page works fine on the same machine.

If I copy my code into the Sample Project, it works. This means the code is correct. And web service is always OK if open asmx page and test it.

My project was created by selecting template of AJAX Enabled website, and then copy the AjaxControlToolkit.dll from Toolkit Sample project Bin folder to my project Bin folder. And then add reference to it. Very standard way.

I compared the difference of the sample project and my project, basically the reference. The only difference is that, the AjaxControlToolkit.dll in my project is versioned as "Auto Update", while in sample project it's versioned as 1.0.61121.0. BUT I DON"T KNOW HOW TO CREATE A PROJECT WITH REFERENCE OF THIS FILE TO BE VERSIONED AS 1.0.61121.0.

For your info, my code is mainly posted as following:

<!-- for aspx code: -->

<asp:DropDownList ID="DropDownList1" runat="server" Width="200px"></asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1" Category="Carrier" PromptText="Please select a carrier" LoadingText="[Loading carriers...]" ServicePath="uscarrier.asmx" ServiceMethod="ReturnUSCarriers"></ajaxToolkit:CascadingDropDown>

// webservice code
[WebMethod]
[Microsoft.Web.Script.Services.ScriptMethod()]
public CascadingDropDownNameValue[] ReturnUSCarriers(string knownCategoryValues, string category)
{
SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString_Prod"].ConnectionString);
SqlCommand cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select distinct Name, OperatorID from [CMS_Carriers] where OperatorID like '3%' and IsActive = 1";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "Carriers");

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

for (int i = 0; i < ds.Tables["Carriers"].Rows.Count; i++)
{
DataRow dr = ds.Tables["Carriers"].Rows[i];
carriervalues.Add(new CascadingDropDownNameValue((string)dr["Name"], dr["MBloxOperatorID"].ToString()));
}
return carriervalues.ToArray();
}

The ReturnUSCarriers method needs to be static. (This is covered in the ASP.NET AJAX migration docs as well ashttp://blogs.msdn.com/sburke/archive/2006/10/21/hint-components-that-use-web-services-with-asp-net-ajax-v1-0-beta.aspx.)

David:

Thanks for your reply. I set the method to be static, and it still does not work.


If this is a page method (looks like it is), then you may want to try removing the ServicePath property entirely.
my cascading dropdowns are no longer working as well. I am calling an external web service with the same method signiture as above.
also, this was after I upgraded to the RC and updated control kit.

figured it out, for some reason I was missing this in my web.config:

<addverb="GET,HEAD"path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"validate="false"/>


Shoot, I just realized those were needed for the Ajax to work in IE. And by me removing those lines from the web.config it just does a normal postback and not an asynchronous call. That is why it worked for me. So really nothing has changed. I am back to nothing on why the response.redirect() doesn't work. You guys mentioned that you took the code and were able to get the response.redirect() to work. I'm not sure what in my environment could be any different. I'm running this off of localhost and I do not have IIS running.

Saturday, March 24, 2012

Want to use something other than a xmldocument to feed the cascading dropdown list

I'm starting to use the toolkit and the first control I'm working on is the cascading dropdown list. I'm messing with the web service right now. The example uses an xmldocument for the source of the data. My data is already being returned in the form of a list. Can I make that work or do I have to turn my data into an xmldocument? Hopefully not.

Thanks for the help

Hi,

Yes, you can make this work. All you really need to do is implement a web method that returns an array of CascadingDropDownNameValue objects. Check outhttp://ajax.asp.net/ajaxtoolkit/Walkthrough/CCDWithDB.aspx for an example. Just map your list of items to CascadingDRopDownNameValue objects and you should be good.

Thanks,
Ted

Wednesday, March 21, 2012

web method error in cascadingDropdown

i am trying to use the cascading dropdownlist control, using a web service to get items from a database. the web method works fine, but i get a web method error 404 or 500. any help in solving this would be greatly appreciated.

Hi, mnyats.

I solved right now (telling the true, in this exact minute) a problem I was facing that was generating this same error message. In my case the problem was:

1 - I was trying to make cascadingDropDown to work with no service; (I guess it's possible but all the samples I got on the web says no)

2 - On the call of my service, inside my aspx page, I forgot to include the full namespace of the service;

3 - The service was with the attribute: <System.Web.Script.Services.ScriptService()> commented.

I don't know which problem are you having now, but I hope this can help...

See you!@.!

<mnyats> escreveu na mensagemnews:1966118@.forums.asp.net...

i am trying to use the cascading dropdownlist control, using a web service to get items from a database. the web method works fine, but i get a web method error 404 or 500. any help in solving this would be greatly appreciated.

http://forums.asp.net/p/1172554/1966118.aspx#1966118


Hi,

I think Fiddler is a good choice for you to trouble shooting. Please refer to this thread: http://forums.asp.net/t/1172379.aspx