2013-05-02 59 views
0

我有一个ImageField的是只能使用一次的第一次显示消息框,但是当我使用取消按钮来关闭消息框,在这里是怎么了asp.net按钮工作一次,然后停止工作

<script type="text/javascript"> 
$(document).ready(function() { 

$('#<%= imagebutton1.ClientID %>').click(function() { 
     alert('hello'); // ONLY WORKS once 
     $.blockUI({message: $('#mainInsert')}); 
    }); 

$('#<%= Button2.ClientID %>').click(function() { 
     $.unblockUI(); 
    }); 
}); 
</script> 

这里我怎么definsedh我的图像按钮

<br /> 
<asp:ImageButton ID="imagebutton1" runat="server" ImageAlign="Right" ImageUrl="/_layouts/n.png" /> 
<br /> 
<br /> 

这里的取消按钮的代码,

<div id="mainInsert" style="display: none; cursor: default"> 
    <asp:Button ID="Button2" Text="Cancel" runat="server" CssClass="rightButton" /> 
</div> 

回答

0

取而代之的是,

$('#<%= imagebutton1.ClientID %>').click(function() { 

我用onclick,把代码中的自定义JS功能,使其工作,作为回传它是失去连接到控件的事件。

0

您可能bubblin通过其他事件。一定要通过父母和孩子的点击事件停止传播。

<script type="text/javascript"> 
$(document).ready(function() { 

$('#<%= imagebutton1.ClientID %>').click(function(event) { 
     alert('hello'); // ONLY WORKS once 
     $.blockUI({message: $('#mainInsert')}); 
     event.stopPropagation(); 
    }); 

$('#<%= Button2.ClientID %>').click(function(event) { 
     $.unblockUI(); 
     event.stopPropagation(); 
    }); 
}); 
</script> 

我不确定能否解决这个问题,但这似乎是一个很好的第一枪。

乔伊

+0

谢谢,但现在每次我点击imagebutton它显示消息框,但然后刷新页面自动分裂秒 – Mathematics 2013-05-02 13:56:18