ASP.Net-< select> jQuery填充列表后未回发的项目 [英] ASP.Net -- <select> items not being posted back after jQuery populates list

查看:71
本文介绍了ASP.Net-< select> jQuery填充列表后未回发的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.Net ListBox,我正在尝试使用以下代码段通过jQuery进行填充:

I have an ASP.Net ListBox that I'm trying to populate via jQuery, using the following snippet:

    $("#MyList_btnAddAll").click(function(e) {
    e.preventDefault();
    $('#MyList_lstAll option').appendTo('#MyList_lstSelected');
});

该代码实际上有两个ListBox,一个是源",另一个是目的地".正如您在上方可以看到的,列表框是MyList_lstAll和MyList_lstSelected.正如您所期望的那样,这些元素在浏览器中呈现为元素.

The code has two ListBoxes in fact, one a "source" and the other a "destination". As you can tell above the ListBoxes are MyList_lstAll and MyList_lstSelected. These are rendered in the browser as elements, as you'd expect.

jQuery很好用,项目从一个ListBox移到另一个,DOM更新了,但是当我发布页面时,回发并不表示对ListBox进行任何更改.我知道有一些涉及jQuery和ASP.Net回发的陷阱,但是有人可以指导我一些可能发生的事情以及如何使它起作用吗?

The jQuery is working great, the items are moving from one ListBox to the other, the DOM is updated but when I post my page, the postback doesn't indicate any change to the ListBox. I know there are gotchas involving jQuery and ASP.Net postbacks, but could someone guide me a bit as to what's going on possibly and how I can get this to work?

根据要求,这里提供了更多的ASP.Net和HTML.下面是保存它们的ascx控件中的ListBox和按钮声明:

By request, here's some more of the ASP.Net and HTML resulting. Below are the ListBox and button declarations in the ascx control that holds them:

 <GLP:ListBox ID="lstAll" CssClass="LIST_BOX_MEDIUM" runat="server" SelectionMode="Multiple"/>

<asp:LinkButton ID="lnkAddAll2" CssClass="LIST_SELECT" runat="server" OnClick="btnAddAll_Click"/>

<GLP:ListBox ID="lstSelected" CssClass="LIST_BOX_MEDIUM" runat="server" SelectionMode="Multiple"/>

以及生成的HTML:

<select class="LIST_BOX_MEDIUM" id="MyList_lstAll" multiple="multiple" name="MyList:lstAll" size="4">
 <option value="641">Item1</option><option value="598">Item2</option>
</select>

<input type="submit" class="BUTTON_SMALL_N0_IMAGE" id="MyList_btnAddAll" value="Add All" name="MyList:btnAddAll" style="color: rgb(0, 0, 0);">

<select class="LIST_BOX_MEDIUM" id="MyList_lstSelected" multiple="multiple" name="MyList:lstSelected" size="4">
 <option value="642">Item3</option><option value="599">Item4</option>
</select>

我知道jQuery/ListBox项的修改不会反映在ViewState中,但是由于它们是在页面发布时位于DOM中的,因此不会将它们包含在回发数据中,然后由各自的控件提取吗?

I know the jQuery/ListBox item modifications aren't reflected in ViewState, but since they're in the DOM when the page is posted wouldn't they be included in the postback data and then picked up by their respective controls?

推荐答案

我认为您需要直接从请求中获取选择的项目列表,而不是从asp.net控件属性中获取,例如:

I think you will need to get the seletcted item list directly from the request, rather thsn from the asp.net control properties, like this:

string results = Request.Form[list_box.UniqueID];

这篇关于ASP.Net-&lt; select&gt; jQuery填充列表后未回发的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆