我在尝试获取用户输入的弹出窗口中有一个 DropDownList。我还有一个用于获取用户输入的“onselectedIndexChanged”。我将整个 DropDownList 放在 updatePanel 中,因此只有 DropDownList 得到更新。(弹出窗口是使用 JQuery/JS 构建的)我使用 JS 到 hiddenfield 值然后将其传递给另一个函数)这是我的代码:
<div id="ddlFiles">
<label>
Select new CaseFile:</label>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<asp:DropDownList runat="server" ID="ddlCaseFilesNew" DataSourceID="dsCaseFiles"
DataTextField="Display" DataValueField="FileID" OnPreRender="ddl_PreRender" Width="300px"
AutoPostBack="true" OnSelectedIndexChanged="ddlCaseFilesNew_SelectedIndexChanged">
<asp:ListItem>Item 1</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlCaseFilesNew" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
这是我的 selectedIndexChanged:
<script runat="server">
protected void ddlCaseFilesNew_SelectedIndexChanged(object sender, EventArgs e)
{
hidNewCaseFile.Value = ddlCaseFilesNew.SelectedItem.Value;
}
</script>
现在由于某种原因,只要我从列表中选择某些内容,它就会将我发送到“找不到资源”页面。我不知道为什么会这样。我的网址如下所示:
http://localhost:49355/base/Expenses/ViewExpenses.aspx?CaseFileID=2001
当我尝试选择一个值时,它会打开该错误(找不到资源)页面并说我找不到链接。
这是错误的图片:
页面加载:
Response.Cache.SetAllowResponseInBrowserHistory(false);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (!isLoggedIn())
return;
if (Request.QueryString["ExpenseID"] != null)
{
if (!IsPostBack)
{
ddlCaseFilesNew.DataSourceID = "dsCaseFiles";
ddlCaseFilesNew.SelectedIndex = -1;
ddlCaseFilesNew.DataTextField = "Display";
ddlCaseFilesNew.DataValueField = "FileID";
ddlCaseFilesNew.DataBind();
if (Request.QueryString["CaseFileID"] != null) // from view>casefiles>casefile#>notes
hidCaseFile.Value = Request.QueryString["CaseFileID"].ToString();
}
}
if (Request.QueryString["CaseFileID"] != null) // from view>casefiles>casefile#>notes
hidCaseFile.Value = Request.QueryString["CaseFileID"].ToString();
else if (Request.QueryString["FileID"] != null && Request.QueryString["TaskID"] != null) // from view>task>specific task notes
{
hidCaseFile.Value = Request.QueryString["FileID"].ToString();
hidTaskID.Value = Request.QueryString["TaskID"].ToString();
}
}
protected void ddl_PreRender(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
try
{
if (ddl.Items[0].Value != "-1")
ddl.Items.Insert(0, new ListItem("--Select--", "-1"));
}
catch
{
ddl.Items.Insert(0, new ListItem("--Select--", "-1"));
}
}