当从下拉列表(asp:Dropdownlist)中选择一个项目时,我想使用blockUI来阻止页面。选择项目(onchange 事件)时,UI 确实会“被阻止”,但仍处于阻止状态。似乎回发事件没有被触发。当我单击回发到服务器的按钮,处理它需要的内容并返回并取消阻止页面时,我能够阻止和取消阻止 UI。我无法从下拉列表中让它做同样的事情。有什么建议么?
<script type="text/javascript">
var URL;
function showWaitPanel(msg) {
$.blockUI({
message: '<p>' + msg + '</p>'
,css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff' }
});
}
function removeWaitPanel(msg, url) {
$.unblockUI();
if (msg != '') {
$.blockUI({ message: '' + msg + '' });
setTimeout($.unblockUI, 20000);
}
if (url != '')
window.location.href = url;
}
</script>
<asp:DropDownList ID="ddlVendors" runat="server" AppendDataBoundItems="true" AutoPostBack="true" OnSelectedIndexChanged="ddlVendors_SelectedIndexChanged" >
……
在服务器端,代码隐藏,... Page_Load(...) {
if (!Page.IsPostBack)
{
ddlVendors.Attributes.Add("onchange", "return showWaitPanel('Please Wait...');");
}
}
protected void ddlVendors_SelectedIndexChanged(object sender, EventArgs e)
{
.....
RemoveWaitPanel("ddlVendors_SelectedIndexChanged", "", "");
}
private void RemoveWaitPanel(string key, string message, string url)
{
string strScript = "return removeWaitPanel('" + message + "', '" + url + "');";
ScriptManager.RegisterClientScriptBlock(this, GetType(), key, strScript, true);
}
客户端的 showWaitPanel() 确实在选择项目时执行,UI 被阻止但服务器端 ddlVendors_SelectedIndexChanged (postback) 没有被执行