错误 500 - CascadingDropDown AJAX Extender 工具包控件

发布于 2024-09-15 15:30:25 字数 4691 浏览 4 评论 0原文

我正在尝试使用 CascadingDropDown 填充 3 个下拉列表。 DDL 分别显示汽车的品牌、型号和颜色。数据驻留在 .xml 文件中。

最后一个 DDL 具有 AutoPostBack = true,我试图在一个标签控件中显示下拉列表中的值。

我正在从 Web 服务中提取数据来填充 DDL。我在编译时没有收到任何错误,但当我运行代码时,它显示错误 500。我不确定哪里出错了。我正在关注“我该怎么做”的教程视频 -

http://www.asp.net/ajax/videos/how-do-i-use-the-aspnet-ajax-cascadingdropdown-control-extender

我正在使用 C#和.Net框架2.0。

我的 Web 服务 看起来像这样 -

[WebService(Namespace = "http://tempuri.org/< /a>")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService()] public class CarsService : System.Web.Services.WebService {

public XmlDataDocument _document;
//public object _lock = new Object();
public CarsService () {

    //Uncomment the following line if using designed components 
    //InitializeComponent(); 
}

public XmlDocument Document
 {
     get
     {
         if (_document==null)
         {
             _document = new XmlDataDocument();
             _document.Load(HttpContext.Current.Server.MapPath("~/App_Data/CarsService.xml"));
         }
         //Document = _document;
         return _document;
     }
 }

public string[] Hierarchy
{
    get
    {
        string[] hierarchy = {"make","model"};
        return hierarchy;
    }

}

[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knowncategoryvalues, string category)
{
    StringDictionary knownCategoryValuesDictionary = new StringDictionary();
    knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knowncategoryvalues);

    return  AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category);

}

}

网页看起来像这样 -

无标题页面

    <br />
    <br />

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:DropDownList ID="DropDownList1" runat="server" Width="147px">
            </asp:DropDownList>
            <br />
            <asp:DropDownList ID="DropDownList2" runat="server" Width="147px">
            </asp:DropDownList>
            <br />
            <asp:DropDownList ID="DropDownList3" runat="server" Width="147px" 
                AutoPostBack="True">
            </asp:DropDownList>
            <br />
            <br />
            <br />
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <br />
            <br />
            <asp:TextBox ID="TextBox1" runat="server" Height="64px" Width="191px"></asp:TextBox>
            <br />
            <br />
            <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" 
                Category="make" PromptText="Please enter dish name" 
                ServiceMethod="GetDropDownContents" TargetControlID="DropDownList1" 
                ServicePath="CarsService.asmx">
            </ajaxToolkit:CascadingDropDown>
            <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" 
                Category="model" LoadingText="[Loading price...]" 
                ParentControlID="DropDownList1" PromptText="Please select price" 
                ServiceMethod="GetDropDownContents" TargetControlID="DropDownList2">
            </ajaxToolkit:CascadingDropDown>
            <ajaxToolkit:CascadingDropDown ID="CascadingDropDown3" runat="server" 
                Category="color" LoadingText="[Loading Description...]" 
                ParentControlID="DropDownList2" PromptText="Select Description" 
                ServiceMethod="GetDropDownContents" TargetControlID="DropDownList3">
            </ajaxToolkit:CascadingDropDown>
            <br />
            <br />
            <br />
            <br />
        </ContentTemplate>
    </asp:UpdatePanel>
</form>

还在这里附加 xml 文件 -

我不确定我哪里出错了。你能帮我吗?

I am trying to populate 3 dropdown lists with using CascadingDropDown. DDLs shows make, model and color of a car respectively. Data resides in a .xml file.

The last DDL is having AutoPostBack = true and I am trying to display the values from dropdown in one label control.

I am pulling data from a webservice to populate DDLs. I am not getting any error while compiling but when I run the code it shows Error 500. I am not sure where I am going wrong. I am following the tutorial video of 'How Do I' -

http://www.asp.net/ajax/videos/how-do-i-use-the-aspnet-ajax-cascadingdropdown-control-extender

I am using C# and .Net framework 2.0.

My Web Service looks like this -

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class CarsService : System.Web.Services.WebService {

public XmlDataDocument _document;
//public object _lock = new Object();
public CarsService () {

    //Uncomment the following line if using designed components 
    //InitializeComponent(); 
}

public XmlDocument Document
 {
     get
     {
         if (_document==null)
         {
             _document = new XmlDataDocument();
             _document.Load(HttpContext.Current.Server.MapPath("~/App_Data/CarsService.xml"));
         }
         //Document = _document;
         return _document;
     }
 }

public string[] Hierarchy
{
    get
    {
        string[] hierarchy = {"make","model"};
        return hierarchy;
    }

}

[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knowncategoryvalues, string category)
{
    StringDictionary knownCategoryValuesDictionary = new StringDictionary();
    knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knowncategoryvalues);

    return  AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category);

}

}

And Web page looks like this -

Untitled Page

    <br />
    <br />

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:DropDownList ID="DropDownList1" runat="server" Width="147px">
            </asp:DropDownList>
            <br />
            <asp:DropDownList ID="DropDownList2" runat="server" Width="147px">
            </asp:DropDownList>
            <br />
            <asp:DropDownList ID="DropDownList3" runat="server" Width="147px" 
                AutoPostBack="True">
            </asp:DropDownList>
            <br />
            <br />
            <br />
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <br />
            <br />
            <asp:TextBox ID="TextBox1" runat="server" Height="64px" Width="191px"></asp:TextBox>
            <br />
            <br />
            <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" 
                Category="make" PromptText="Please enter dish name" 
                ServiceMethod="GetDropDownContents" TargetControlID="DropDownList1" 
                ServicePath="CarsService.asmx">
            </ajaxToolkit:CascadingDropDown>
            <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" 
                Category="model" LoadingText="[Loading price...]" 
                ParentControlID="DropDownList1" PromptText="Please select price" 
                ServiceMethod="GetDropDownContents" TargetControlID="DropDownList2">
            </ajaxToolkit:CascadingDropDown>
            <ajaxToolkit:CascadingDropDown ID="CascadingDropDown3" runat="server" 
                Category="color" LoadingText="[Loading Description...]" 
                ParentControlID="DropDownList2" PromptText="Select Description" 
                ServiceMethod="GetDropDownContents" TargetControlID="DropDownList3">
            </ajaxToolkit:CascadingDropDown>
            <br />
            <br />
            <br />
            <br />
        </ContentTemplate>
    </asp:UpdatePanel>
</form>

Attaching xml file also here -

I am not sure where I am going wrong. Can you please help me ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小沫ゞ 2024-09-22 15:30:25

Firebug 对于调试 Web 服务调用非常有用。

  1. 安装适用于 Firefox 的 Firebug 插件
  2. 在 Firefox 中打开测试网页
  3. 打开 Firebug,然后打开 Net 选项卡并单击 XHR
  4. 再次尝试下拉列表并在 XHR 响应中查找错误

Firebug is invaluable for debugging web service calls.

  1. Install the Firebug plugin for Firefox
  2. Open your test web page in Firefox
  3. Open Firebug, then open the Net tab and click on XHR
  4. Try your drop down again and look for the error in the XHR response
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文