I want my selectable to work as an autopostback control, when something is selected the script clicks on a button and postback the values of the selectable. 但它不能很好地与我的 ASP.NET Ajax 和 UpdatePanels 配合使用。有时会发生完整的回发,而不是部分回发。
我从调试中得出的结论是,当停止函数运行时,jQuery 在幕后做了一些事情。如果我添加警报以停止停止功能,则部分回发可以正常工作。
为了增加一些混乱,这适用于IE9
and Chrome
,但不适用于IE7
or IE8
。所以它也可能是特定于浏览器的。
jQuery版本为:v1.6.2
脚本:
<script language="javascript">
$('.selectable').live("mouseover", function () {
if (!$(this).data("selectable-init")) {
$(this).data("selectable-init", true);
$(this).selectable({
filter: '.item',
stop: function () {
$("#<% =btnPostback.ClientID %>").click();
}
});
}
});
</script>
HTML:
<div class="selectable">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Literal ID="litIsPostback" runat="server"></asp:Literal>
<asp:Button ID="btnPostback" runat="server" OnClick="btnPostback_OnClick" />
</ContentTemplate>
</asp:UpdatePanel>
后面的代码:
protected void btnPostback_OnClick(object sender, EventArgs e)
{
litIsPostback.Text = ScriptManager.GetCurrent(this).IsInAsyncPostBack.ToString();
}