【问题标题】:DropDownList selection is not reflected in server sideDropDownList 选择未反映在服务器端
【发布时间】:2012-07-20 08:13:32
【问题描述】:

我的 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;

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

提前致谢。

【问题讨论】:

标签: c# jquery asp.net ajax drop-down-menu


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2010-09-16
    • 1970-01-01
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多