Html 使用更新面板更新部分页面
我正在创建“编辑我的个人资料页面”,在这里我有一些文本框和下拉列表。我有一个要求,当我在第一个下拉列表中选择一个值时,第二个下拉列表应该填充。但这并没有发生Html 使用更新面板更新部分页面,html,asp.net,c#-4.0,Html,Asp.net,C# 4.0,我正在创建“编辑我的个人资料页面”,在这里我有一些文本框和下拉列表。我有一个要求,当我在第一个下拉列表中选择一个值时,第二个下拉列表应该填充。但这并没有发生 <asp:UpdatePanel runat="server" ID="updatepanel1" UpdateMode="Conditional"> <ContentTemplate > <asp:
<asp:UpdatePanel runat="server" ID="updatepanel1" UpdateMode="Conditional">
<ContentTemplate >
<asp:Label runat="server" Id="lbljobIndus" Text="Preferred Job Industry" Font-Names="Calibri" Font-Size="Small" ForeColor="Black"></asp:Label>
<span style="color: black; font-family: Calibri; font-size: small">:</span>
<asp:Label runat="server" ID="lblPreferredJobIndustry" Font-Names="Calibri" Font-Size="Small" ForeColor="Black"></asp:Label>
<asp:DropDownList ID="tbPreferredJobIndustry" runat="server" Height="19px" OnSelectedIndexChanged="ddlTargetedIndustry_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="-1">--Select Industry--</asp:ListItem>
<asp:ListItem Value="1">Administration</asp:ListItem>
<asp:ListItem Value="2">Hospital/HealthCare</asp:ListItem>
<asp:ListItem Value="3">Medical Transcription</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
<asp:Label runat="server" ID="lblJobCat" Text="Preferred Job Category" Font-Names="Calibri" Font-Size="Small" ForeColor="Black"></asp:Label>
<span style="color: black; font-family: Calibri; font-size: small">:</span>
<asp:Label runat="server" ID="lblJobCategory" Font-Names="Calibri" Font-Size="Small" ForeColor="Black"></asp:Label>
<asp:DropDownList ID="tbJobCategory" runat="server">
<asp:ListItem Selected="True" Value="-1">-Position Category-</asp:ListItem>
</asp:DropDownList>
<br />
<br />
</ContentTemplate>
</asp:UpdatePanel>
我使用了“更新”面板,以便其他文本框中的值不会在回发邮件时被清除。但是现在,我认为回发没有发生。你能检查我的代码并告诉我错误在哪里吗?为第一个ddl设置AutoPostBack=true你可以使用它非常有用。但是如果发生CascadingDropDown,您需要额外的服务
<ajaxToolkit:CascadingDropDown ID="CDD1" runat="server"
TargetControlID="DropDownList2"
Category="Model"
PromptText="Please select a model"
LoadingText="[Loading models...]"
ServicePath="CarsService.asmx"
ServiceMethod="GetDropDownContents"
ParentControlID="DropDownList1"
SelectedValue="SomeValue" />
[System.Web.Script.Services.ScriptService]
公共类CarsService:WebService
{
//成员变量
私有静态XmlDocument\u文档;
私有静态Regex\u输入验证Regex;
私有静态对象_lock=新对象();
//我们公开这些静态数据只是为了让我们可以从外部调用它们
//页面方法调用
公共静态XML文档
{
得到
{
锁
{
如果(_document==null)
{
//从磁盘读取XML数据
_document=新的XmlDocument();
_Load(HttpContext.Current.Server.MapPath(“~/App_Data/CarsService.xml”);
}
}
返回文件;
}
}
公共静态字符串[]层次结构
{
获取{返回新字符串[]{“make”,“model”};}
}
公共静态正则表达式InputValidationRegex
{
得到
{
锁
{
if(null==\u inputValidationRegex)
{
_inputValidationRegex=新的正则表达式(“^[0-9a-zA-Z\\(\\)]*$”;
}
}
返回inputValidationRegex;
}
}
///
///助手web服务方法
///
///专用存储格式字符串
///要填充的DropDownList的类别
///内容项列表
[网络方法]
公共AjaxControlToolkit.CascadingDropDownNameValue[]GetDropDownContents(字符串知识类别值,字符串类别)
{
//获取已知类别/值对的字典
StringDictionary knownCategoryValuesDictionary=AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
//对数据文档执行简单查询
返回AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(文档、层次结构、知识类别值字典、类别、InputValidationRegex);
}
我将其设置为“true”但是,它仍然不起作用。现在发生的是,当我在第一个ddl中更改我的选择时,两个ddl都消失了!!可能有一些验证错误,请尝试CausesValidation='false'检查原因。两个ddl的验证都设置为false。我有页面代码来填充第二个下拉列表。那么我应该离开ServicePath和Service吗方法设置为NULL?然后在哪里指定填充第二个下拉列表的方法?
<ajaxToolkit:CascadingDropDown ID="CDD1" runat="server"
TargetControlID="DropDownList2"
Category="Model"
PromptText="Please select a model"
LoadingText="[Loading models...]"
ServicePath="CarsService.asmx"
ServiceMethod="GetDropDownContents"
ParentControlID="DropDownList1"
SelectedValue="SomeValue" />
<asp:DropDownList ID="DropDownList1" runat="server" Width="170" />
<asp:DropDownList ID="DropDownList2" runat="server" Width="170" />
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1"
Category="Make" PromptText="Please select a make" LoadingText="[Loading makes...]"
ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents" />
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static CascadingDropDownNameValue[] GetDropDownContentsPageMethod(string knownCategoryValues, string category)
{
return new CarsService().GetDropDownContents(knownCategoryValues, category);
}
<%@ WebService
Language="C#"
CodeBehind="~/App_Code/CarsService.cs"
Class="CarsService" %>
[System.Web.Script.Services.ScriptService]
public class CarsService : WebService
{
// Member variables
private static XmlDocument _document;
private static Regex _inputValidationRegex;
private static object _lock = new object();
// we make these public statics just so we can call them from externally for the
// page method call
public static XmlDocument Document
{
get
{
lock (_lock)
{
if (_document == null)
{
// Read XML data from disk
_document = new XmlDocument();
_document.Load(HttpContext.Current.Server.MapPath("~/App_Data/CarsService.xml"));
}
}
return _document;
}
}
public static string[] Hierarchy
{
get { return new string[] { "make", "model" }; }
}
public static Regex InputValidationRegex
{
get
{
lock (_lock)
{
if (null == _inputValidationRegex)
{
_inputValidationRegex = new Regex("^[0-9a-zA-Z \\(\\)]*$");
}
}
return _inputValidationRegex;
}
}
/// <summary>
/// Helper web service method
/// </summary>
/// <param name="knownCategoryValues">private storage format string</param>
/// <param name="category">category of DropDownList to populate</param>
/// <returns>list of content items</returns>
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
{
// Get a dictionary of known category/value pairs
StringDictionary knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
// Perform a simple query against the data document
return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category, InputValidationRegex);
}