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.
No comments:
Post a Comment