0

我的 asp.net 网页中有一个下拉列表。它是一个服务器端控件。我正在做一个 ajax 调用,在 ajax 调用中我正在向 ddl 添加一个新项目并将其设置为选中状态。它在页面上显示得很好。但是当我回发时,所选项目会在下拉列表中为我提供旧的所选项目。

// ddlCaseNumber is the id of the dropdownlist and its clientid property is set
// to static.
// Removes the selected attribute of selected selected item .
$('#ddlCaseNumber option:selected').removeAttr("selected");

// Add the new item to dropdownlist.
$('#ddlCaseNumber').append('<option selected="selected" value=' + crmid + '>' 
                           + crmid + '</option>');

// Code behind code to get the new value.
// This line is giving the old value instead of giving new value.
string strNewValue = ddlCaseNumber.SelectedItem.Value;

谁能告诉我如何在后面的代码中添加新项目?

提前致谢。

4

1 回答 1

2

在客户端上动态添加的项目不会在回发时自动复制到服务器上。

一种选择是以某种方式存储已添加的新项目(以 a<input type="hidden">或之类的方式<asp:HiddenField>),然后手动将项目添加为Init回发页面的一部分。

另一种选择是调用 AJAX 将服务器上的信息存储在Session变量中,然后在回发时再次手动添加。

于 2012-07-20T08:17:52.250 回答