简体   繁体   English

下拉列表未触发索引更改事件

[英]Drop Down List not triggering Index changed event

My drop down list triggers code behind on index change when I use this, 当我使用此下拉列表时,它会触发索引更改背后的代码,

$('#messagebox').show();

but NOT triggering event when I use, 但在使用时不会触发事件,

 $.blockUI({message: $('#messagebox'), css: { width: '600px' } });

Here's my markup for div where drop down is, appears like a message box 这是我在div下拉菜单中的标记,看起来像一个消息框

<div id="messagebox" style="display: none; cursor: default">
   <asp:DropDownList ID="ddl" runat="server" EnableViewState="true" AutoPostBack="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged"/>
</div>

How can I solve this issue ? 我该如何解决这个问题?

This is most likely because blockUI is appending the content to the body, instead of to the form tag. 这很可能是因为blockUI会将内容附加到正文而不是form标签。 Asp.Net controls will not post back events if they are outside of the form tag, so you run into it often when appending elements to the body with javascript. 如果它们不在form标记之外,Asp.Net控件将不会回发事件,因此在使用javascript将元素附加到正文时,您经常会遇到该事件。 You will most likely have to make a couple of amendments to BlockUI. 您很可能必须对BlockUI进行一些修改。

For more info, see this answer: https://stackoverflow.com/a/7929700/1346464 . 有关更多信息,请参见以下答案: https : //stackoverflow.com/a/7929700/1346464

Edit: 编辑:

Summarising the linked answer (based on blockUI v2.59.0-2013.04.05, which is the latest at time of writing): 总结链接的答案(基于撰写本文时的最新版本的blockUI v2.59.0-2013.04.05):

On line 319 (search for var layers ), replace $('body') with $('form') . 在第319行(搜索var layers )上,将$('body')替换$('body') $('form')

On line 336 (search for $('html,body').css('height','100%'); ), replace $('html,body') with $('html,body,form') . 在第336行上(搜索$('html,body').css('height','100%'); ),将$('html,body')替换$('html,body,form')

Edit 2: 编辑2:

Fixes unblocking: 修复了解锁:

On line 448 (search for els = $('body').children().filter('.blockUI').add('body > .blockUI'); ) replace both instances of body with form . 在第448行(搜索els = $('body').children().filter('.blockUI').add('body > .blockUI'); )将两个body实例替换为form

I'm not familiar with jQuery blockUI, but with jQuery Dialog, it removes any form fields from the form when it is displayed. 我不熟悉jQuery blockUI,但是使用jQuery Dialog时,它会在显示表单时从表单中删除所有表单字段。 Therefore, when the form is posted back, you don't have access to them. 因此,将表单发回时,您无权访问它们。

With jQuery Dialog, you have to add some code to get the fields added back to the form. 使用jQuery Dialog,您必须添加一些代码才能将字段添加回表单中。 I'd recommend searching to see if blockUI has the same issue. 我建议搜索以查看blockUI是否存在相同的问题。

autopostbackproperty=true like  below

<asp:DropDownList ID="ddlName"  runat="server" AutoPostBack ="true"
    onselectedindexchanged="ddlName_SelectedIndexChanged" >
</asp:DropDownList>

protected void ddlName_SelectedIndexChanged(object sender, EventArgs e)
{

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM